AssignmentGuru

Solution: Reddit: HCICZX: Checking for empty input or invali

Jun 20th, 2016
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1. # http://python.assignmentsolutionguru.com/
  2.  
  3. numlist = []
  4. while True:
  5.     try:
  6.         temp = input('Enter a number or press "Enter" to finish: ')
  7.         if temp == "": # "Enter" pressed, break the loop
  8.             break
  9.            
  10.         tempint = int(temp)
  11.         numlist.append(tempint)
  12.         print(numlist)
  13.     except ValueError:
  14.         # Could not convert the input to Integer, bad input
  15.         print('Please enter an integer.')
  16.  
  17. print(numlist)
  18.  
  19. # http://python.assignmentsolutionguru.com/
Add Comment
Please, Sign In to add comment