First Term
First Term
Area = L * L
Perimeter = 4 * L
print("The area of the square is:", Area, "\nThe perimeter of the square is:", Perimeter)
import cmath
import math
ch = int(input(
"Enter 1 to print the area and circumference of a circle\nEnter 2 to print the area and perimeter
of a rectangle\nEnter your choice: "))
if ch == 1:
r = float(input("Enter the radius of the circle: "))
print("The area of the circle is: ", math.pi * (math.pow(r, 2)))
print("The circumference of the circle is: ", (2 * math.pi * r))
elif ch == 2:
l = float(input("Enter the length of the rectangle: "))
w = float(input("Enter the width of the rectangle: "))
print("The area of the rectangle is: ", (l * w))
print("The perimeter of the rectangle is: ", 2 * (l + w))
else:
print("Wrong choice! Try again!")
n = int(input("Enter the value of 'N' to print the sum of the first 'N' natural numbers: "))
s=0
for x in range(1, n + 1):
s += x
print("The sum of the first '", n, "' natural numbers is: ", s)
# Procedure – 2 Write a python script to input temperature as per user choice: 1- Celsius Scale to
Fahrenheit Scale 2- Fahrenheit Scale to Celsius Scale.
ch = int(input(
"Enter '1' for conversion from Celsius to Fahrenheit scale\nEnter '2' for conversion from
Fahrenheit to Celsius scale\nEnter your choice:"))
if ch == 1:
C = float(input("Enter temperature in Celsius(°C): "))
F = (C * (9 / 5)) + 32
print("The given temperature in Fahrenheit is: " + str(F) + "°F")
elif ch == 2:
F = float(input("Enter temperature in fahrenheit(°F): "))
C = (5 / 9) * (F - 32)
print("The given temperature in celsius is: " + str(C) + "°C")
else:
print("Wrong choice! Try Again!")
# Selection – 1 Write a python script to input 4 numbers and display the largest of them.
A = float(input("Enter first number: "))
B = float(input("Enter second number: "))
C = float(input("Enter third number: "))
D = float(input("Enter fourth number: "))
if (A > B) and (A > C) and (A > D):
largest = A
elif (B > A) and (B > C) and (B > D):
largest = B
elif (C > A) and (C > B) and (C > D):
largest = C
else:
largest = D
print("The smallest number is: ", largest)
# Selection – 2 Write a python script to check whether a year is Leap Year or not.
year = int(input("Enter a year: "))
if (year % 4) == 0:
if (year % 100) == 0:
if (year % 400) == 0:
print(year, "is a leap year")
else:
print(year, "is not a leap year")
else:
print(year, "is a leap year")
else:
print(year, "is not a leap year")
# Selection – 3 Write a python script to solve the quadratic equation ax2 + bx + c = 0 where a ≠
0, stating the nature of roots.
# Write a python script to calculate and display the result of n∑(k**2) , k=1 where N is accepted
as user input.
n = int(input("Enter the value of 'N' to print the sum: "))
s=0
for k in range(1, n + 1):
s += k ** 2
print("The sum is: ", s)
# Iteration – 2 Write a python script to input a number and print its factorial value.
n = int(input("Enter the number: "))
s=1
for x in range(1, (n + 1)):
s *= x
print("The factorial of '" + str(n) + "' is: ", s)
# Iteration – 3 Write a python script to read a number and check it is prime or not.
n = int(input("Enter a number: "))
c=0
for x in range(1, n):
if (n % x) == 0:
c += 1
if c == 1:
print(n, "is a prime number")
else:
print(n, "isn't a prime number")
# Iteration – 4 Write a python script to read a number and calculate the sum of its digits.
n = int(input("Enter a variable: "))
s=0
while n != 0:
s += int(n % 10)
n /= 10
print("Sum of the digits is: ", s)
# Iteration – 6 Write a python script(s) to calculate the sum of the following series :
# i. S = 1 + x + x^2 + x^3 + ….. + x^n
# ii. S = 1 + x – x^2/2!+ x^3/3! – ….. up to n terms
# iii. S = 1 + (1+2) + (1+2+3) + ….. + (1+2+3+ ….. + n)
# iv. S= 0 + 1 + 1 + 2 + 3 + ….. up to n terms.
ch = int(input("Enter your choice: "))
n = int(input("Enter the value of 'n': "))
x = float(input("Enter the value of 'x': "))
s=0
if ch == 1:
for i in range(1, n + 1):
s += x ** i
print("The sum is: ", s + 1)
elif ch == 2:
for i in range(1, n + 1):
f=1
for j in range(1, (i + 1)):
f *= j
if i % 2 == 0:
s -= (x ** i) / f
elif i % 2 == 1:
s += (x ** i) / f
print("The sum is: ", s + 1)
elif ch == 3:
for i in range(1, n + 1):
s += i * (i + 1) / 2
print("The sum is: ", s)
elif ch == 4:
n1, n2, c, s = 0, 1, 0, 0
while c < n:
s += n1
n3 = n1 + n2
n1 = n2
n2 = n3
c += 1
print("The sum is: ", s)
else:
print("Wrong choice! Try Again!")
# List – 1 Write a python script to create two list of integers L1[ ] and L2[ ] respectively , then
join L2[ ] in reverse order after L1[ ].
L1 = eval(input("Enter the elements of L1 in [ ] separated by ',' : "))
L2 = eval(input("Enter the elements of L2 in [ ] separated by ',' : "))
L2.reverse()
L1.extend(L2)
print(L1)
# List – 2 Write a python script to create a list of integers and count the number of integers
ending with 5.
L1 = eval(input("Enter the elements in [ ] separated by ',' : "))
c=0
for i in L1:
if i % 10 == 5:
c=c+1
print("The number of integers ending in '5' are: ", c)
# List – 3 Write a python script to implement linear search in a user inputted list of integers.
L1 = eval(input("Enter the elements in [ ] separated by ',' : "))
x = int(input("Enter the element to be searched for: "))
for i in range(len(L1)):
if L1[i] == x:
print("The element '", x, "' is present in ", L1, " at the position of: ", i + 1)
# List – 4 Write a python script to implement bubble sort in a user inputted list of integers.
L1 = eval(input("Enter the elements in [ ] separated by ',' : "))
for i in range(len(L1)):
for j in range(len(L1) - 1):
if L1[j] > L1[j + 1]:
t = L1[j]
L1[j] = L1[j + 1]
L1[j + 1] = t
print("The sorted list is: ", L1)