## ❮ Back

In [ ]:
'''Write a program that takes the name and age of the user as input and displays a message whether the user is eligible
to apply for a driving license or not. (the eligible age is 18 years)'''
age = int(input("Enter your age: "))
if age >= 18:
print("Eligible")
else:
print("Not Eligible")

In [ ]:
'''Write a function to print the table of a given number.The number has to be entered by the user.'''
num = int(input("Enter number: "))
for i in range(1,11):
print(i*num)

In [ ]:
'''Write a program that prints minimum and maximum of five numbers entered by the user.'''
max = int(input("Enter first number: "))
min = max
for i in range(4):
num = int(input("Enter number: "))
if num > max:
max = num
elif num<min:
min = num
else:
continue
print("Max is: " + str(max))
print("Min is: " + str(min))


In [ ]:
"""Write a program to check if the year entered by the user is a leap year or not."""
year = int(input("Enter: "))
if year % 4 == 0 and year % 100 != 0:
print("leap")
elif year%4 ==0 and year %400 == 0:
print("leap")
else:
print("not leap")

In [ ]:
 """Write a program to generate the sequence: –5, 10, –15, 20, –25….. upto n, where n is an integer input by the user"""
n = int(input("Enter the value of n"))

for i in range(1,(n//5 +1)):
num = (5 * i) * (-1)**i
print(num, end=", ")

In [ ]:
"""Write a program to find the sum of 1+ 1/8 + 1/27......1/n3, where n is the number input by the user."""
sums = 0
n = int(input("Enter the value of n: "))
for i in range(1,n+1):
sums += (1/(i**3))
print(sums)

In [ ]:
"""Write a program to find the sum of digits of an integer number, input by the user."""
digits = input("Enter number: ")
sums = 0
for i in digits:
sums += int(i)
print(sums)

In [ ]:
"""Write a function that checks whether an input number is a palindrome or not."""
num = int(input("Enter number:"))
copy = num
reverse = 0
while(copy>0):
dig = copy % 10
reverse = reverse*10 + dig
copy=copy//10
if(num==reverse):
print("Palindrome")
else:
print("Not a palindrome")

In [ ]:
"""Write a program to print the following patterns:"""
sp = " "
#a)
for i in range(3):
print(sp*(2-i) + "*" * (1 + 2*i) + sp*(2-i))
for i in range(2):
print(sp*(i+1) + "*" * (3-2*i) + sp*(i+1))
print("______\n")
#b)
print(sp*5 + "1" + sp*5)
st = "1"
for i in range(2,6):
st = str(i) + st + str(i)
print(sp*(6-i) + st + sp*(6-i))
print("______\n")
#c
num = "12345"
i = 5
while i != 0:
print(sp*(5-i) + num[0:i])
i -=1
print("______\n")

In [ ]:
"""Write a program to find the grade of a student when
grades are allocated as given in the table below.
Above 90%            A
80% to 90%           B
70% to 80%           C
60% to 70%           D
Below 60%            E

Percentage of the marks obtained by the student is input
to the program."""

percent = int(input("Enter Percentage: "))
if percent > 90:
print("A")
elif 80 <= percent < 90: #treated as percent>=80 and percent<90
print("B")
elif 70 <= percent < 80:
print("C")
elif 60 <= percent < 70:
print("D")
elif percent < 60:
print("E")
else:
print("Invalud Input")