students = [] #this assigns the first student list, and is empty grades = [] #this assigns the first grades list, and is empty grades2D = [] #this assigns the first and the grades and names list, and is empty while True: print("Option1: Enter a score") #When the program is first run it displays the three lines of instructions: print("Option2: Display the grades") print("Option3: Exit") #the "option =" creates a changeable variable because it is followed by an "input" command option = input("Enter option here: ").strip().lower() #using .strip() removes any blank spaces either before or after the input, and .lower() changes the input to all lowercase if option == "1": #the == means that if option entered above is equal to 1 then this if statement runs #if "1" in option: #this may be a more usuful command as if the user doesnt just enter 1 then it will still work. name = input("Enter the students name: ") #"name =" creates an object called name, and then makes it equal to whatever is typed score = int(input("Please enter the score between 0 & 100 you wish to convert: ")) if score <0: #if the score is lower than 0 then this piece of code runs print("You can't have a negative score") #and displays this print elif score <=30: #otherwiise it runs this elif code students.append(name) #this adds the name defined earlier to the "students" list grades.append("U") #this adds the grade to the end of the "grades" list grades2D.append([name, "U"]) grades2D.append([name, "U"]) #this adds both the name followed by the grade to a seperate list elif score <=40: #if the above elif is not run then this one will be run instead students.append(name) grades.append("E") grades2D.append([name, "E"]) elif score <=50: students.append(name) grades.append("D") grades2D.append([name, "D"]) elif score <=60: students.append(name) grades.append("C") grades2D.append([name, "C"]) elif score <=70: students.append(name) grades.append("B") grades2D.append([name, "B"]) elif score <=100: students.append(name) grades.append("A") grades2D.append([name, "A"]) elif score >100: #this section is here to make sure that data is entered correctly, and so no values over 100 can be entered print("You can't have a score greater than 100") else: #this else command is used to cover any other possibilities print("Please enter a number between 0 and 100") elif option == "2": #this checks to see if option 2 is chosen #if "2" in option: #this may be a more usuful command as if the user doesnt just enter 1 then it will still work. counter = 0 #this creates a counter variable, and sets it equal to 0 for student in students: #this says for all the individual student added to the students list, and repeats the code until they're all done print(student + " achieved a " + grades[counter] + " grade") #print their name, the text, then their grade using the counter counter +=1 #then add one relative to the counter elif option == "3": #if "3" in option: #this may be a more usuful command as if the user doesnt just enter 1 then it will still work. break #This section of code breaks the script at this point, which closes the program. elif option == "4": #this is a hidden option and is another way of displaying their grades. #if "4" in option: #this may be a more usuful command as if the user doesnt just enter 1 then it will still work. for students in grades2D: #this says repeat for all the students in the grades2D list 1 print(student[0] + " achieved a " + student[1] + " grade") # this will print the students name then their grade through just one list else: #otherwsie it will print the below message. print("Please enter a valid choice of 1,2 or 3")
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question