I have a code where the user is asked to input two integers, separated by a " ". This should continue as long as the user does not input anything, causing a ValueError, and breaking the While loop. However, I can't figure out what am I doing wrong:
def syote():
koepisteet_all = []
harjoitukset_all = []
while True:
koepisteet, harjoitukset = input('Koepisteet ja harjoitusten määrä: ').split()
if ValueError:
break
else:
koepisteet_all.append(koepisteet)
harjoitukset_all.append(harjoitukset)
print(koepisteet_all)
print(harjoitukset_all)
if __name__ == "__main__":
syote()
As wished, I do get a ValueError "ValueError: not enough values to unpack (expected 2, got 0)", but the code stops running.
try/except
to catch errors, notif
. – Barmarsyote()
ends after the while loop. Did you want the two print statements to be executed after the loop? Then you have to indent them correctly. – jps