114k views
2 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

1 Answer

2 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 Leesio
by
7.9k points

No related questions found

Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.