I want to break this loop when I press ENTER then display the list but it doesn't recognize '' since it has to be a string
list = []
while True:
try:
num = int(input('Enter integers:'))
list.append(num)
except ValueError:
print('Not an integer, try again')
continue
if num == '':
list.sort()
print(list)
break
I also want to display "x is not an integer, try again." but I keep getting an error when I try
print(num + 'is not and integer, try again.')
listis a bad variable name since it shadows the builtinlisttype. In example code it's not a big problem, just confusing, but it'd be better to use a more descriptive name likenumbers. Cf. Why does "example = list(...)" result in "TypeError: 'list' object is not callable"?.