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

Ai- Python Programs1742702182467

The document contains multiple Python programs that demonstrate various functionalities such as finding the largest of three numbers, checking if a number is odd or even, printing the Fibonacci series, checking for prime numbers, displaying patterns, calculating average and highest marks, and converting Fahrenheit to Celsius. Each program includes user input and outputs the results accordingly. The document serves as a collection of basic programming exercises in Python.

Uploaded by

sriswathivg10
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)
5 views5 pages

Ai- Python Programs1742702182467

The document contains multiple Python programs that demonstrate various functionalities such as finding the largest of three numbers, checking if a number is odd or even, printing the Fibonacci series, checking for prime numbers, displaying patterns, calculating average and highest marks, and converting Fahrenheit to Celsius. Each program includes user input and outputs the results accordingly. The document serves as a collection of basic programming exercises in Python.

Uploaded by

sriswathivg10
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/ 5

1.

# Python program to find the largest of three numbers

# Input from user

num1 = float(input("Enter first number: "))

num2 = float(input("Enter second number: "))

num3 = float(input("Enter third number: "))

# Compare the numbers

if (num1 >= num2) and (num1 >= num3):

largest = num1

elif (num2 >= num1) and (num2 >= num3):

largest = num2

else:

largest = num3

# Display the result

print("The largest number is:”,largest)

2. # Python program to check if a number is odd or even

# Input from user

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

# Check if the number is divisible by 2

if num % 2 == 0:

print(num, “ is an Even number.")

else:

print(num, “ is an Odd number.")


3. # Python program to print Fibonacci series of 30 terms

# First two terms

n1, n2 = 0, 1

print("Fibonacci series up to 30 terms:")

print(n1, end=' ')

print(n2, end=' ')

# Loop to print 30 terms

For i in range(30):

n3 = n1 + n2

print(n3, end=' ')

# Update values for next iteration

n1 = n2

n2 = n3

4. Program to check prime or not


# n is the number to be check whether it is prime or not
n = 10

# this flag maintains status whether the n is prime or not


prime = 1

for i in range(2, n):


if (n % i == 0):
prime = 0
break
if (prime_flag == 0):
print("True")
else:
print("False")
5. Program to display the following pattern

for i in range(1,5):

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

print(j,end=" ")

print()

6. Python program to store English subject marks of 10


students
and display the average and highest mark

# Create an empty list to store marks


english_marks = []

# Input marks for 10 students


for i in range(1, 11):
mark = float(input("Enter English mark for student : "))
english_marks.append(mark)

# Calculate average
average_mark = sum(english_marks) / len(english_marks)

# Find highest mark


highest_mark = max(english_marks)

# Display results
print("\nMarks of 10 students:", english_marks)
print("Average mark:”,average_mark)
print("Highest mark:”,highest_mark)
7. Program to print all the odd numbers using for loop(Get the range from the user)

maxlimit=int(input(“Enter the maximum limit”))

for i in range(1,maxlimit,2)

print(i)

8. Program to print all the odd numbers using while loop(Get the range from the user)

maxlimit=int(input(“Enter the maximum limit”))

i=0

while(i<=maxlimit)

print(i)

i=i+1

9. # Python program to convert Fahrenheit to Celsius

# Input temperature in Fahrenheit

fah = float(input("Enter temperature in Fahrenheit: "))

# Conversion formula

cel = (faht - 32) * 5/9

# Display result

print(fah, “ °F is equal to ”,cel, “°C")

You might also like