0% found this document useful (0 votes)
3 views

Ankit Assignment

Uploaded by

nopakeb103
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Ankit Assignment

Uploaded by

nopakeb103
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

10/13/24, 10:42 PM Ankit Assignment

ICT lab\Ankit Assignment

1 #1. Arithmetic Calculations


2 # Addition, subtraction, multiplication, division
3 print(5 + 3)
4 print(10 - 4)
5 print(6 * 7)
6 print(8 / 2)
7
8 #2. Operators Demonstration
9 a = 10
10 b = 5
11
12 # Arithmetic
13 print(a + b)
14 print(a - b)
15
16 # Relational
17 print(a > b)
18
19 # Logical
20 print(a > 5 and b < 10)
21
22 # Augmented
23 a += 5
24 print(a)
25
26 # Membership
27 print('H' in 'Hello')
28
29 # Identity
30 print(a is b)
31
32 # Bitwise
33 print(a & b)
34
35 #3. Sum and Product of Two Numbers
36 a = int(input("Enter first number: "))
37 b = int(input("Enter second number: "))
38 print("Sum:", a + b)
39 print("Product:", a * b)
40
41 #4. Largest of Three Numbers
42 a = int(input("Enter first number: "))
43 b = int(input("Enter second number: "))
44 c = int(input("Enter third number: "))
45 print("Largest number:", max(a, b, c))
46
47 #5. Average Marks in 'n' Subjects
48 n = int(input("Enter number of subjects: "))
49 total = 0
50 for i in range(n):
51 marks = float(input(f"Enter marks for subject {i+1}: "))

localhost:60985/f6c4103b-6610-4d74-99c8-160aecad55c1/ 1/3
10/13/24, 10:42 PM Ankit Assignment

52 total += marks
53 print("Average Marks:", total / n)
54
55 #6. Solve a Quadratic Equation
56 import math
57 a = float(input("Enter coefficient a: "))
58 b = float(input("Enter coefficient b: "))
59 c = float(input("Enter coefficient c: "))
60 discriminant = b**2 - 4*a*c
61 if discriminant >= 0:
62 root1 = (-b + math.sqrt(discriminant)) / (2*a)
63 root2 = (-b - math.sqrt(discriminant)) / (2*a)
64 print(f"Roots are: {root1} and {root2}")
65 else:
66 print("Complex roots")
67
68 #7. Area and Perimeter of a Rectangle
69 length = float(input("Enter the length of the rectangle: "))
70 width = float(input("Enter the width of the rectangle: "))
71 area = length * width
72 perimeter = 2 * (length + width)
73 print(f"Area: {area}, Perimeter: {perimeter}")
74
75 #8. Menu-Driven Area Calculator
76 import math
77
78 print("Menu:")
79 print("1. Area of Circle")
80 print("2. Area of Rectangle")
81 print("3. Area of Square")
82 choice = int(input("Enter your choice: "))
83
84 if choice == 1:
85 r = float(input("Enter radius of circle: "))
86 print("Area of Circle:", math.pi * r**2)
87 elif choice == 2:
88 l = float(input("Enter length: "))
89 w = float(input("Enter width: "))
90 print("Area of Rectangle:", l * w)
91 elif choice == 3:
92 s = float(input("Enter side of square: "))
93 print("Area of Square:", s**2)
94 else:
95 print("Invalid choice")
96
97 #9. Fibonacci Series Using While Loop
98 limit = int(input("Enter limit for Fibonacci series: "))
99 a, b = 0, 1
100 while a < limit:
101 print(a, end=" ")
102 a, b = b, a + b
103
104 #10. Printing Patterns python
105 # Pattern 1
localhost:60985/f6c4103b-6610-4d74-99c8-160aecad55c1/ 2/3
10/13/24, 10:42 PM Ankit Assignment

106 for i in range(4):


107 print("5 5 5 5")
108
109 # Pattern 2
110 for i in range(1, 5):
111 for j in range(1, i+1):
112 print(j, end=" ")
113 print()
114
115 #11. Sum of First 'n' Numbers Using For Loop python
116 n = int(input("Enter the value of n: "))
117 total = 0
118 for i in range(1, n+1):
119 total += i
120 print("Sum of first", n, "numbers:", total)
121
122 #12. Body Mass Index (BMI)
123 weight = float(input("Enter your weight in kg: "))
124 height = float(input("Enter your height in meters: "))
125 bmi = weight / (height ** 2)
126 print("Your BMI is:", bmi)
127
128 #13. Sort Three Integers Without Conditionals or Loops
129 a = int(input("Enter first number: "))
130 b = int(input("Enter second number: "))
131 c = int(input("Enter third number: "))
132 sorted_numbers = sorted([a, b, c])
133 print("Sorted numbers:", sorted_numbers)
134
135 #14. Maximum of 10 Numbers
136 numbers = []
137 for i in range(10):
138 numbers.append(int(input(f"Enter number {i+1}: ")))
139 print("Maximum number is:", max(numbers))
140
141 #15. Check if String is a Palindrome
142 s = input("Enter a string: ")
143 if s == s[::-1]:
144 print("The string is a palindrome")
145 else:
146 print("The string is not a palindrome")

localhost:60985/f6c4103b-6610-4d74-99c8-160aecad55c1/ 3/3

You might also like