Write a program to input 6 numbers. After each number is input, print the biggest of the numbers entered so far.
Answers
Answer:
num1 = int(input("Enter a number: " ))
print("Largest: " + str(num1))
# num 2 #
num2 = int(input("Enter a number: "))
if num2 > num1:
print("Largest: " + str(num2))
else:
print("Largest: " + str(num1))
# num 3 #
num3 = int(input("Enter a number: "))
print("Largest: " + str(max(num1, num2, num3)))
# num 4 #
num4 = int(input("Enter a number: "))
print("Largest: " + str(max(num1, num2, num3, num4)))
# num 5 #
num5 = int(input("Enter a number: "))
print("Largest: " + str(max(num1, num2, num3, num4, num5)))
# num 6 #
num6 = int(input("Enter a number: "))
print("Largest: " + str(max(num1, num2, num3, num4, num5, num6)))
Explanation:
Program in Python,
biggest=0
for i in range(0,6):
num = int(input("Enter the number = "))
if num>biggest:
biggest=num
print("Biggest number is",biggest)
- The loop is looping 6 times as given in the question.
- Assuming the value of the largest number as 0.
- Firstly, the input is taking place.
- Then, the entered number is compared to the previous value of biggest after every iteration.
- At the end of every loop, the biggest number is being printed.