Correct number or “end” 3

Remember when I was trying to have a code for “Give a number or give ‘end’ to exit:” “Give a number or give ‘end’ to exit:”

Proceeding to the amazing course I am taking our teacher gave the following solution:

while True:
  given = input('Give number:')
  if given == 'end':
    break
  try:
    given = int(given)
  except ValueError:
    continue
  #do the following logic inside the while true loop
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s