2025
Python
2
programs
NAME:PARTH
CLASS:+1 ROSE(N.M)
ROLL NO.:21
Sumbit to : computer science teacher
3
4
5 #1 Program to add two
6 numbers by taking input.
7 >>num1 = float(input("Enter first number:
8 "))
9 num2 = float(input("Enter second number:
10 "))
11 sum = num1 + num2
12 print("Te sum is:", sum)
13
14 #2 Program to calculate
15 the area of a rectangle
16 by taking input.
17 >>length = float(input("Enter the length
18 of the rectangle: "))
19 width = float(input("Enter the width of
20 the rectangle: "))
21 area = length * width
22 print("The area of the rectangle is:",
23 area)
24
25 #3 Program to calculate
26 the square of a number
27 by taking input.
28 number = float(input("Enter a number to
29 find its square: "))
30 square = number ** 2
31 print("The square of the number is:",
32 square)
33
34 #4 Program to calculate
35 the cube of a number
36 using exponent operator
37 num = float(input("Enter a number to find
38 its cube: "))
39 cube = num ** 3
40 print("The cube of the number is:", cube)
41 No index entries
42 found.
43 #5 Program to check
44 whether a number is even
45 or odd.
46 >>num_check = int(input("Enter a number
47 to check if it is even or odd: "))
48 if num_check % 2 == 0:
49 print("The number is even.")
50 else:
51 print("The number is odd.")
52
53 #6 Program to calculate
54 the average of three
55 numbers
56 >>num_a = float(input("Enter the first
57 number: "))
58 num_b = float(input("Enter the second
59 number: "))
60 num_c = float(input("Enter the third
61 number: "))
62 average = (num_a + num_b + num_c) / 3
63 print("The average of the three numbers
64 is:", average)
65
66 #7 Program to create a
67 list and display it on
68 the screen.
69 >>my_list = []
70 num_elements = int(input("How many
71 elements do you want in the list? "))
72 for i in range(num_elements):
73 element = input(f"Enter element
74 {i+1}: ")
75 my_list.append(element)
76 print("The list you created is:",
77 my_list)
78
79 #8 Program to add an
80 element in the list
81 using append() function.
82 >>new_element = input("Enter an element
83 to add to the list: ")
84 my_list.append(new_element)
85 print("The updated list is:", my_list)
86
87 #9 Program to add
88 elements of two lists by
89 using concatenation.
90 >>list1 = []
91 list2 = []
92 n1 = int(input("How many elements in the
93 first list? "))
94 for i in range(n1):
95 elem1 = input(f"Enter element {i+1}
96 for first list: ")
97 list1.append(elem1)
98 n2 = int(input("How many elements in the
99 second list? "))
100 for i in range(n2):
101 elem2 = input(f"Enter element {i+1}
102 for second list: ")
103 list2.append(elem2)
104 concatenated_list = list1 + list2
105 print("The concatenated list is:",
106 concatenated_list)
107
108
109 #10 Program to print the
110 table of 5
111 >>print("Multiplication table of 5:")
112 for i in range(1, 11):
113 print(f"5 x {i} = {5 * i}")
114
115
116
117
118
119
120
121