Python Forum
I have a problem with user enter, any help?
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I have a problem with user enter, any help?
#1
[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 ?
Reply
#2
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
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#3
(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 :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Problem restricting user input in my rock paper scissors game ashergreen 6 4,576 Mar-25-2021, 03:54 AM
Last Post: deanhystad
  Problem with user defined main menu function stefzeer 3 2,383 Mar-27-2020, 06:12 AM
Last Post: buran
  new user coding problem mattkrebs 1 3,014 Mar-21-2017, 12:45 PM
Last Post: buran
  MySQLdb, problem with query with user-defined variables buran 6 6,380 Feb-03-2017, 06:16 PM
Last Post: buran
  Python Instagram bot user-following problem danotto 1 5,019 Dec-11-2016, 10:36 PM
Last Post: Blue Dog

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020