0% found this document useful (0 votes)
4 views5 pages

Python Programs for Basic Tasks

The document contains several Python programming tasks including displaying Fibonacci sequence terms, checking leap years, determining grades based on marks, mapping numbers to days of the week, calculating the sum of numbers, displaying multiples of a number, and calculating the factorial of a number. Each task is accompanied by code snippets and example outputs. The code examples demonstrate basic programming concepts such as loops, conditionals, and user input.

Uploaded by

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

Python Programs for Basic Tasks

The document contains several Python programming tasks including displaying Fibonacci sequence terms, checking leap years, determining grades based on marks, mapping numbers to days of the week, calculating the sum of numbers, displaying multiples of a number, and calculating the factorial of a number. Each task is accompanied by code snippets and example outputs. The code examples demonstrate basic programming concepts such as loops, conditionals, and user input.

Uploaded by

GAUTAM reddy
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1) Write a Python Program to display the terms in a Fibonacci sequence

n=int(input(“enter terms”:))

a=0

b=1

print(a)

print(b)

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

temp=a+b

print(a)

a=b

b=temp

Output:

Enter terms:

2)write a Python Program to check whether a year is a leap year or not.

# Ask the user to enter a year

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

# Check if the year is a leap year

if year % 4 == 0:

if year % 100 == 0:

if year % 400 == 0:

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

else:

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

else:

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


else:

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

Output:

Enter a year: 2025

2025 not a leap year.

3)write a python program to input marks and display grade

# Ask the user to enter their marks

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

# Determine the grade based on the marks

if marks >= 90:

grade = "A+"

elif 81 <= marks <= 90:

grade = "A"

elif 71 <= marks <= 80:

grade = "B"

elif 61 <= marks <= 70:

grade = "C"

else:

grade = "U"

# Display the grade

print(f"Your grade is {grade}.")

output:

Enter your marks: 100


Your grade is A+.

4) Write a Python Program to input a number between 1 and 7. The user must be entering
until the number is in range. F0or the input, display corresponding day.

# Ask the user to enter a number between 1 and 7

number = int(input("Enter a number between 1 and 7: "))

# Keep asking until the number is in the range

while number < 1 or number > 7:

print("Invalid input. Please try again.")

number = int(input("Enter a number between 1 and 7: "))

# Display the corresponding day

if number == 1:

print("The day is Monday.")

elif number == 2:

print("The day is Tuesday.")

elif number == 3:

print("The day is Wednesday.")

elif number == 4:

print("The day is Thursday.")

elif number == 5:

print("The day is Friday.")

elif number == 6:

print("The day is Saturday.")

elif number == 7:

print("The day is Sunday.")


output:

Enter a number between 1 and 7: 3

The day is Wednesday.

5) Write a Python Program to calcuate the sum of numbers from 1 to user specified number.

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

total = 0

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

total += i

print(f"The sum of numbers from 1 to {user_input} is {total}")

output:

Enter a number: 3

The sum of numbers from 1 to 3 is 6

6) Write a Python Program to display first ten multiples of n.

n=int(input("enter a number:"))

for i in range(1, 11):

print(n * i)

output:

enter a number:45

45

90

135

180

225
270

315

360

405

450

7) pp to calculate the factorial of a given number by using a loop

num=int(input("enter a number :"))

result = 1

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

result *= 1

print(f"The factorial of {num} is {result}")

output:

enter a number:10

The factorial of 10 is 1

8)

You might also like