0% found this document useful (0 votes)
6 views

AL-Python Programming-Revision1

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.

Uploaded by

Fizzy Wizzy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

AL-Python Programming-Revision1

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.

Uploaded by

Fizzy Wizzy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Python Programming – Revision 1

# 1. Program to find average of three numbers


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"))

if num1 > num2:


print(num1, "is larger")
else:
print(num2, "is larger")

# 5. program to find the largest of two numbers using Procedure


def FindLargest(num1, num2):
if num1 > num2:
print(num1, "is larger")
else:
print(num2, "is larger")

# Main program
n1 = int(input("Enter the first number"))
n2 = int(input("Enter the second number"))
FindLargest(n1, n2)

You might also like