2332988 BTAIML503-20
Program 8: To find the largest of three numbers.
Code:
# Program to find largest of three numbers
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
if a >= b and a >= c:
print("Largest number is:", a)
elif b >= a and b >= c:
print("Largest number is:", b)
else:
print("Largest number is:", c)
Output:
2332988 BTAIML503-20
Program 9: Program to convert temperatures to and from
Celsius, Fahrenheit.
[ Formula: c/5 = f-32/9]
Code:
# Celsius to Fahrenheit and Fahrenheit to Celsius
choice = input("Enter C to convert Celsius->Fahrenheit or F to convert Fahrenheit->C: ")
if [Link]() == "C":
c = float(input("Enter temperature in Celsius: "))
f = (c * 9/5) + 32
print("Temperature in Fahrenheit:", f)
elif [Link]() == "F":
f = float(input("Enter temperature in Fahrenheit: "))
c = (f - 32) * 5/9
print("Temperature in Celsius:", c)
else:
print("Invalid choice!")
Output:
2332988 BTAIML503-20
Program 10: Program to construct a star pattern using nested FOR loop
Code:
# Star Pattern using nested loops
n=5
# Upper half
for i in range(1, n+1):
for j in range(i):
print("*", end=" ")
print()
# Lower half
for i in range(n-1, 0, -1):
for j in range(i):
print("*", end=" ")
print()
Output:
2332988 BTAIML503-20
Program 11: Program to print prime numbers less than 20.
Code:
# Print prime numbers less than 20
print("Prime numbers less than 20:")
for num in range(2, 20):
is_prime = True
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
is_prime = False
break
if is_prime:
print(num, end=" ")
Output: