0% found this document useful (0 votes)
4 views1 page

Python Programs1

The document contains several Python code snippets for different functionalities, including converting Celsius to Fahrenheit, checking if a number is odd or even, determining if a number is prime, generating Fibonacci series using recursion, calculating grades based on marks in three subjects, and finding the maximum number in a list. Each code snippet prompts the user for input and performs the respective calculations or checks. The document serves as a collection of basic programming exercises in Python.

Uploaded by

Saravana Kumar
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 views1 page

Python Programs1

The document contains several Python code snippets for different functionalities, including converting Celsius to Fahrenheit, checking if a number is odd or even, determining if a number is prime, generating Fibonacci series using recursion, calculating grades based on marks in three subjects, and finding the maximum number in a list. Each code snippet prompts the user for input and performs the respective calculations or checks. The document serves as a collection of basic programming exercises in Python.

Uploaded by

Saravana Kumar
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

CELSIUS TO FAHRENHEIT

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


f= (c * 1.8) + 32
print(f)

ODD OR EVEN
num = int(input("Enter a number: "))
if (num % 2) == 0:
print("Even Number ")
else:
print("Odd Number")

PRIME OR NOT
num = int(input("Enter a number: "))
for i in range(2,num):
if (num % i) == 0:
print(“not a prime number")
break
else:
print("prime number")

FIBONACCI SERIES ( USING RECURSION )


def fibo(n):
if n <= 1:
return n
else:
return(fibo(n-1) + fibo(n-2))
nterms= int(input("Enter a number: "))
for i in range(nterms):
print(fibo(i))

GRADE CALCULATION ( 3 SUBJECTS )


sub1=int(input("Enter marks of first subject: "))
sub2=int(input("Enter marks of second subject: "))
sub3=int(input("Enter marks of third subject: "))
avg=(sub1+sub2+sub3) / 3
if(avg>=90):
print("Grade: A")
elif(avg>=80 & avg<90):
print("Grade: B")
elif(avg>=70 & avg<80):
print("Grade: C")
elif(avg>=60 & avg<70):
print("Grade: D")
else:
print("Grade: F")

MAXIMUM IN A LIST
l1=[ 3 , 5 , 22 , 7 ]
maxi = 0
for a in l1:
if a > maxi:
maxi = a
print(maxi)

You might also like