(Apr-25-2020, 12:32 PM)deanhystad Wrote: Really close, but you use assignment to add to a dictionary.
dictionary[key] = value
items = {}
print("Welcome to the Marks Calculator! ")
while True:
studentID = int(input("Enter Student ID >> "))
atMark = float(input("Enter Assessable Tutorial mark (/10) >> "))
asMark = float(input("Enter Assignment mark (/100) >> "))
exMark = float(input("Enter Exam mark (/150) >> "))
finalGrade = int(asMark*20/100)+(exMark*70/150)+atMark
items[studentID] = finalGrade # This is how you add to a dictionary
proceed = input("Would you like to process another student’s marks?(Y/N)>> ")
if proceed.upper() != "Y":
break:
for studentID, finalGrade in items.items():
print(studentID, finalGrade)
print("Program has terminated, goodbye!")
The only code inside a loop should be code you want to run over an over. Did you want to print the welcome each time a student was added? Student marks are echoed at the end of the program, so put that at the end of the program.
Hi deanhystad,
I run your code but for some reason I didn't get any output.
items = {}
print("Welcome to the Marks Calculator! ")
while True :
studentID = int(input("Enter Student ID >> "))
atMark = float(input("Enter Assessable Tutorial mark (/10) >> "))
asMark = float(input("Enter Assignment mark (/100) >> "))
exMark = float(input("Enter Exam mark (/150) >> "))
finalGrade = int(asMark * 20 / 100) + (exMark * 70 / 150) + atMark
items[studentID] = finalGrade
proceed = input("Would you like to process another student’s marks?(Y/N)>> ")
if proceed.upper() != "Y":
break;
for studentID, finalGrade in items.items():
print(studentID, finalGrade)
print("Program has terminated, goodbye!")
Welcome to the Marks Calculator!
Enter Student ID >> 20481792
Enter Assessable Tutorial mark (/10) >> 7
Enter Assignment mark (/100) >> 45
Enter Exam mark (/150) >> 121
Would you like to process another student’s marks?(Y/N)>> y
Enter Student ID >> 232323
Enter Assessable Tutorial mark (/10) >> 7
Enter Assignment mark (/100) >> 78
Enter Exam mark (/150) >> 98
Would you like to process another student’s marks?(Y/N)>> N
Process finished with exit code 0
Does it mean that the input is not being stored in the variable items?
Kind regards,
Alexis
(Apr-25-2020, 12:38 PM)anbu23 Wrote: >>> items = []
>>>
>>> print("Welcome to the Marks Calculator! ")
Welcome to the Marks Calculator!
>>>
>>> while True:
...
... studentID = int(input("Enter Student ID >> "))
... atMark = float(input("Enter Assessable Tutorial mark (/10) >> "))
... asMark = float(input("Enter Assignment mark (/100) >> "))
... exMark = float(input("Enter Exam mark (/150) >> "))
...
... finalGrade = int(asMark*20/100)+(exMark*70/150)+atMark
... items.append( [studentID, finalGrade] )
...
... proceed = input("Would you like to process another student’s marks?(Y/N)>> ")
...
... if proceed.upper() != "Y":
...
... for studentID, finalGrade in items:
... print(studentID, finalGrade)
...
... print("Program has terminated, goodbye!")
...
... break;
...
Enter Student ID >> 1
Enter Assessable Tutorial mark (/10) >> 7
Enter Assignment mark (/100) >> 56
Enter Exam mark (/150) >> 93
Would you like to process another student’s marks?(Y/N)>> y
Enter Student ID >> 2
Enter Assessable Tutorial mark (/10) >> 9
Enter Assignment mark (/100) >> 90
Enter Exam mark (/150) >> 100
Would you like to process another student’s marks?(Y/N)>> n
1 61.4
2 73.66666666666666
Program has terminated, goodbye!
>>>
Hi anbu23,
I run your code too, but for some reason it's not working for me.... I know that I am missing something but I cannot find the error.
items = []
print("Welcome to the Marks Calculator! ")
while True:
studentID = int(input("Enter Student ID >> "))
atMark = float(input("Enter Assessable Tutorial mark (/10) >> "))
asMark = float(input("Enter Assignment mark (/100) >> "))
exMark = float(input("Enter Exam mark (/150) >> "))
finalGrade = int(asMark*20/100)+(exMark*70/150)+atMark
items.append([studentID, finalGrade])
proceed = input("Would you like to process another student’s marks?(Y/N)>> ")
if proceed.upper() != "Y":
for studentID, finalGrade in items:
print(studentID, finalGrade)
print("Program has terminated, goodbye!")
break;
As you can see below the program never stops and it just show me one result.
Welcome to the Marks Calculator!
Enter Student ID >> 20481792
Enter Assessable Tutorial mark (/10) >> 7
Enter Assignment mark (/100) >> 67
Enter Exam mark (/150) >> 121
Would you like to process another student’s marks?(Y/N)>> y
Enter Student ID >> 5343243
Enter Assessable Tutorial mark (/10) >> 6
Enter Assignment mark (/100) >> 23
Enter Exam mark (/150) >> 89
Would you like to process another student’s marks?(Y/N)>> n
20481792 76.46666666666667
Program has terminated, goodbye!
Enter Student ID >>
Kind regards,
Azure