The document contains Python programs for calculating the average of three numbers using different methods: direct input, while loop, and for loop. It also includes a program to find the largest of two numbers, both through direct comparison and using a function. Each program prompts the user for input and displays the result.
The document contains Python programs for calculating the average of three numbers using different methods: direct input, while loop, and for loop. It also includes a program to find the largest of two numbers, both through direct comparison and using a function. Each program prompts the user for input and displays the result.
n1=int(input("Enter the first number:")) n2=int(input("Enter the second number:")) n3=int(input("Enter the third number:")) sum=n1+n2+n3 avg=sum/3 print("Average is: ", avg)
# 2. Program to find average of three numbers using While loop
Sum=0 avg=0 i=1 print("Enter 3 numbers: ") while (i<=3): num=int(input()) Sum = Sum + num i=i+1 avg=Sum/3 print("Average is:", avg)
# 3. Program to find average of three numbers using For loop
Sum=0 avg=0 print("Enter 3 numbers: ") for i in range(1,4): num=int(input()) Sum = Sum + num avg=Sum/3 print("Average is:", avg)
# 4. program to input 2 numbers and find the largest number
num1 = int(input("Enter the first number")) num2 = int(input("Enter the second number"))