118,766 views
37 votes
37 votes
Python Coding:

Ask the user for 2 numbers
Compare the 2 numbers and print the largest number
Repeatedly ask the user for 2 numbers for comparison until user types STOP

User Prasad S Deshpande
by
2.7k points

1 Answer

22 votes
22 votes

Answer:

# Here we are asking the user for a number two times

userInput1 = input("Enter any #: ")

userInput2 = input("Enter any # again: ")

# We compare if userInput1 is greater than userInput2

if(userInput1 > userInput2):

# Print userInput1 if userInput1 is greather than userInput2

print("First Number: " + userInput1)

# Otherwise, print userInput2

else:

print("Second Number: " + userInput2)

# Initiate a while-loop

while(True):

# The lines below are from above

userInput1 = input("\\Enter any #: ")

userInput2 = input("Enter any # again: ")

if(userInput1 > userInput2):

print("First Number: " + userInput1)

else:

print("Second Number: " + userInput2)

# We ask the user whether they would like to stop

stop = input("\\Would you like to stop? (Yes or No)")

# Compare the String stop with "Yes"

if(stop == "Yes"):

# If true then break

break

Explanation:

The use of \\ is unnecesary, but it skips a line and provides more readability.

User Anurag Wagh
by
3.1k points