I'll try to build on the last suggestion of the accepted answer.
while True:
try:
x = int(input("Enter a number: "))
break
except ValueError:
continue
I definitely endorse this suggestion, it allows your program to handle invalid input gracefully instead of just crashing.
However, it creates an usability problem. The user who just typoed a letter into a number probably did not notice it. They'll think they got the intended number in, proceed with the next, and then get confused at the end, when they think they got all numbers in, but the computer is still asking for the next one.
Better to give them feedback:
while True:
try:
x = int(input("Enter a number: "))
break
except ValueError:
print("Invalid number will be ignored.")
continue
... or even better, print their typoed number back at them:
while True:
try:
inputString = input("Enter a number: ")
x = int(inputString)
break
except ValueError:
print("Invalid number will be ignored: {}".format(inputString))
continue
I would also consider keeping the full list of valid numbers entered, not just odd ones, and printing them all back at the user before the result, to give them a last chance to spot typos. They can, after all, have mistyped a valid but unintended number. Note that this would increase memory usage, and some would consider it over-communication.
print("Numbers provided are: {}".format(all_valid_numbers_inputted))
if not odds:
print("No odd number was entered")
else:
print("The largest odd number is:", max(odds))
If you do this, the next step would be to get rid of the "odds" variable, and figure out the largest odd directly from the full list.
max_odd
and update it if a bigger odd number appears. \$\endgroup\$