Python Forum
taking input doesnt print as list - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/Forum-Python-Coding)
+--- Forum: General Coding Help (https://python-forum.io/Forum-General-Coding-Help)
+--- Thread: taking input doesnt print as list (/Thread-taking-input-doesnt-print-as-list)



taking input doesnt print as list - bntayfur - Jun-04-2020

I am trying to get 10 scores from the user and print them out as a list. instead output is like this

Output:
please enter your discussions scores: 3 [3] please enter your discussions scores: 2 [2] please enter your discussions scores: 1 [1] please enter your discussions scores: 3 [3] please enter your discussions scores: 5 [5] please enter your discussions scores: 4 [4] please enter your discussions scores: 3 [3] please enter your discussions scores: 2 [2] please enter your discussions scores: 1 [1] please enter your discussions scores: 1 [1]
i=1
while i <=10:
    try: 
        my_list = []  
        my_list.append(int(input('please enter your discussions scores: '))) 
        i += 1
        print(my_list)
    
    except: 
        print('you made an error,please try again')

Still doesnt work when i print it outside like this

i=1
while i <=10:
    try: 
        my_list = []  
        my_list.append(int(input('please enter your discussions scores: '))) 
        i += 1
    
    except: 
        print('you made an error,please try again')
print(my_list)




RE: taking input doesnt print as list - michael1789 - Jun-04-2020

Define my_list before the loop.


RE: taking input doesnt print as list - bntayfur - Jun-04-2020

Thank you!