#1 Program to add two
numbers by taking input.
>>num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
sum = num1 + num2
print("Te sum is:", sum)
#2 Program to calculate the
area of a rectangle by taking
input.
>>length = float(input("Enter the length of the rectangle:
"))
width = float(input("Enter the width of the rectangle: "))
area = length * width
print("The area of the rectangle is:", area)
#3 Program to calculate the
square of a number by taking
input.
number = float(input("Enter a number to find its square:
"))
square = number ** 2
print("The square of the number is:", square)
#4 Program to calculate the
cube of a number using
exponent operator
num = float(input("Enter a number to find its cube: "))
cube = num ** 3
print("The cube of the number is:", cube)
No index entries found.
#5 Program to check whether a
number is even or odd.
>>num_check = int(input("Enter a number to check if it is
even or odd: "))
if num_check % 2 == 0:
print("The number is even.")
else:
print("The number is odd.")
#6 Program to calculate the
average of three numbers
>>num_a = float(input("Enter the first number: "))
num_b = float(input("Enter the second number: "))
num_c = float(input("Enter the third number: "))
average = (num_a + num_b + num_c) / 3
print("The average of the three numbers is:", average)
#7 Program to create a list and
display it on the screen.
>>my_list = []
num_elements = int(input("How many elements do you
want in the list? "))
for i in range(num_elements):
element = input(f"Enter element {i+1}: ")
my_list.append(element)
print("The list you created is:", my_list)
#8 Program to add an element
in the list using append()
function.
>>new_element = input("Enter an element to add to the
list: ")
my_list.append(new_element)
print("The updated list is:", my_list)
#9 Program to add elements of
two lists by using
concatenation.
>>list1 = []
list2 = []
n1 = int(input("How many elements in the first list? "))
for i in range(n1):
elem1 = input(f"Enter element {i+1} for first list: ")
list1.append(elem1)
n2 = int(input("How many elements in the second list? "))
for i in range(n2):
elem2 = input(f"Enter element {i+1} for second list: ")
list2.append(elem2)
concatenated_list = list1 + list2
print("The concatenated list is:", concatenated_list)
#10 Program to print the table
of 5
>>print("Multiplication table of 5:")
for i in range(1, 11):
print(f"5 x {i} = {5 * i}")