0% found this document useful (0 votes)
24 views4 pages

1 10

Hg

Uploaded by

sainipranjal19
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views4 pages

1 10

Hg

Uploaded by

sainipranjal19
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

1.

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).

name = input("Enter your name: ")

age = int(input("Enter your age: "))

if age >= 18:

print(f"{name}, you are eligible to apply for a driving license.")

else:

print(f"{name}, you are not eligible to apply for a driving license.")

2. Write a function to print the table of a given number. The number has to be entered by the user.

def print_table(number):

for i in range(1, 11):

print(f"{number} x {i} = {number * i}")

num = int(input("Enter a number to print its table: "))

print_table(num)

3. Write a program that prints minimum and maximum of five numbers entered by the user.
numbers = []

for i in range(5):

num = float(input(f"Enter number {i+1}: "))

numbers.append(num)

min_num = min(numbers)

max_num = max(numbers)

print(f"The minimum number is: {min_num}")

print(f"The maximum number is: {max_num}")


4. Write a program to check if the year entered by the user is a leap year or not.

year = int(input("Enter a year: "))

if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):

print(f"{year} is a leap year.")

else:

print(f"{year} is not a leap year.")

5. 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(-5, n+1, 5):

print(i, end=" ")

6. Write a program to find the sum of 1+ 1/8 + 1/27......1/n3, where n is the number input by the

user.

n = int(input("Enter the value of n: "))

sum_series = 0

for i in range(1, n+1):

sum_series += 1 / (i ** 3)

print(f"The sum of the series is: {sum_series}")

7. Write a program to find the sum of digits of an integer number, input by the user.

number = int(input("Enter an integer: "))


sum_digits = 0

while number > 0:

sum_digits += number % 10 # Adding the last digit to sum

number //= 10 # Removing the last digit

print(f"The sum of digits is: {sum_digits}")

8. Write a function that checks whether an input number is a palindrome or not.

[Note: A number or a string is called palindrome if it appears same when written in reverse order also. For

example, 12321 is a palindrome while 123421 is not a palindrome]

def is_palindrome(num):

num_str = str(num)

if num_str == num_str[::-1]:

return True

else:

return False

number = int(input("Enter a number: "))

if is_palindrome(number):

print(f"{number} is a palindrome.")

else:

print(f"{number} is not a palindrome.")

10. Write a program to find the grade of a student when grades are allocated as given in the table below.

Percentage of Marks Grade


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.

percentage = float(input("Enter the percentage of marks: "))

if percentage > 90:

grade = 'A'

elif 80 <= percentage <= 90:

grade = 'B'

elif 70 <= percentage < 80:

grade = 'C'

elif 60 <= percentage < 70:

grade = 'D'

else:

grade = 'E'

print(f"The grade for {percentage}% is: {grade}")

You might also like