Cs Class
Cs Class
sum=num1+num2
print("sum =",sum)
product=num1*num2
print("product =",product)
power=num1**num2
print("power =",power)
flowdivision=num1//num2
print("flowdivision =",flowdivision)
division=num1/num2
print("division =",division)
multiplication=num1*num2
print("multiplication =",multiplication)
4/7/2024
Control Statement:
8/7/2024
Questions
if (age>=18):
else:
if number > 0:
print("Positive")
print("Negative")
else:
print("Zero")
Q3) Write a program in python to accept two integers and print the
largest.
else:
Q4) Write a program to accept the integers and print the smallest.
(smallest.py)
else:
Q5) Write a program in python that inputs three numbers and calculate
the sums as per this (twosums.py):
Sum1 as the sum of all input numbers
Q6) Program to calculate the amount payable after sales discount, which
is 10% up to the sales amount of 20000 and 17.5% on amounts above
that. (discount.py)
else:
Q7) Write a program in python that asks the user to enter a length in cm.
If the user enters a negative length, the program should tell the user that
the entry is invalid, else the program should convert the length to inches
and print out the result. (1 inch = 2.54cm)
if length_cm < 0:
else:
Q8) A store charges 120rs per item if you buy less than 10 items, if you
buy between 10 and 99 items, the cost is 100rs more per item. If you buy
100 or more items, the cost is 70 rs. Write a python program that asks the
user how many items they are buying and print the cost.
A8) num_items = int(input("Enter the number of items you are buying: "))
cost_per_item = 120
else:
cost_per_item = 70
Q9) Write a python program that reads three numbers(integers) and print
them in ascending order (ascending.py)
A9) num1 = int(input("Enter the first integer: "))
if side1 + side2 > side3 and side2 + side3 > side1 and side3 + side1 >
side2:
else:
Loops
while text_expression:
statement
Q1) Write a program for the sum of integers up to ‘n’ by using while loop.
Q2) Write a program in python to find the sum of the first 20 even
numbers.
Syntax:
Statements
Q1) Write a python program to find sum of the first 10 natural numbers
using for loop and the average.
A1) sum=0
for x in range(1,11):
sum +=x
a=sum/10
print("sum",sum,"average:",a)
HW (12/7/24)
Q1) Print your name 10 times.
for i in range(10):
print(name)
print(i)
if i % 2 == 0:
or
print(i)
if i % 2 != 0:
print(i)
print(i * n, end="\t")
print()
a=0
b=1
print(a)
print(b)
for x in range(1,n-1):
c=a+b
a=b
b=c
print(c)
16/7/2024
SUBSTRINGS:
string_length = len(my_string)
print(string_length)
A2)
Q3) Write a Python program to get a string made of the first 2 and the last
2 chars from a given a string.
SubStrings
Syntax:
string[start:end]
string[:end]
string[start:]
string[start:end:step]
Q1) Write a python program to accept a string, the program will check if a
letter is lowercase, it’ll convert it to uppercase and vice versa.
swapped = ""
if letter.islower():
swapped += letter.upper()
elif letter.isupper():
swapped += letter.lower()
else:
swapped += letter
print(swapped)
19/7/2024
Syntax:
round()
Random
Syntax:
import random
print(random.randint(0,9))
List/Array -
23/7/2024
25/7/2024
Q1) Write a python program that accepts 10 positive integers and counts
all even numbers.
Q2) Write a python program that accepts 10 positive integers and counts
all even numbers.