Python Forum

Full Version: I have a problem with user enter, any help?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
[Image: XalEJUZ][Image: Uy7uE1m]
I'm creating a small Grading System 
I had created a Dictionary called Std = {'Ali':[99,80,21],'Ahmed':[]} stands for Students 
how the program works? 
first you need to register as an admin using Python as a username and 999 as a password (not the best pass ever :))
then you have this welcome String: 
print("""
    Welcome to Grade System
    [1] Enter Grades 
    [2] to remove a student
    [3] to get Average marks
    [4] Exit
    """)
if you enter 1 the program will ask you to enter the student name then student mark 
everything works fine until you enter a student name that does not exist 
the program is suppose to create a new student key and append the mark to that student and add it to the Std dictionary.
it creates a new key and assign the mark to it but [Image: 1JQJfVO]
as you see Ahmed and Ali are already created and have multiple values with [] were Ssss is not treated like them and does not have [] on it  
at line 16 tell 19 I add this code to create a new Student 
else:

        print('Student Does not Exist,Will Add it now!')
        Std[nameToEnter] = int(gradeToadd)
    print(Std)

so how can I insert a new Student  with [] surrounding the mark ?
In Python, a bunch of values closed in [] is called list.
In short, you want to create a new student if his/her name is not in the dict with an empty list as value?
See this
(Mar-20-2017, 06:47 AM)wavic Wrote: [ -> ]In Python, a bunch of values closed in [] is called list.
In short, you want to create a new student if his/her name is not in the dict with an empty list as value?
See this

thanks for your reply 
i did adjust this code 
but it dosnt fitt like I expected
but I did change the code to be 
Std[nameToEnter] = [int(gradeToadd)] 
and it worked! 

thanks again :)