for i in range(5):
mylist[i]=int(input("Input an integer: "))
Do I really still have to define mylist before the for loop before I can actually use it? At the first loop it works fine but at the second loop it will show a NameError do I have to use a different inut method or what?
NameError: name 'mylist' is not defined
Yes, you need to define what "mylist" is before you assign values to it.
mylist = []
for i in range(5):
mylist.append(int(input("Input an integer: ")))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With