Ankit Assignment
Ankit Assignment
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
localhost:60985/f6c4103b-6610-4d74-99c8-160aecad55c1/ 3/3