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

Program 8

The document contains several Python programs demonstrating basic programming concepts. It includes programs to find the largest of three numbers, convert temperatures between Celsius and Fahrenheit, construct a star pattern using nested loops, and print prime numbers less than 20. Each program is accompanied by code snippets and expected outputs.

Uploaded by

haryyjazz2004
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 views4 pages

Program 8

The document contains several Python programs demonstrating basic programming concepts. It includes programs to find the largest of three numbers, convert temperatures between Celsius and Fahrenheit, construct a star pattern using nested loops, and print prime numbers less than 20. Each program is accompanied by code snippets and expected outputs.

Uploaded by

haryyjazz2004
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

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:

You might also like