Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Marks Calculator
#11
(Apr-25-2020, 12:05 PM)anbu23 Wrote:
items = []
.....
    finalGrade = int(asMark*20/100)+(exMark*70/150)+atMark
    items.append( [studentID, finalGrade] )

Hi Anbu23,

Thank you for your help!

Is there another way to code this program by using for? I want to learn as much as possible.
I am gonna use your code though but I want to learn as much as possible about Python.
By the way, I am a bit confused about the order of your code.

I tried this code but I got this error "SyntaxError: multiple statements found while compiling a single statement".

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
	proceed = input("Would you like to process another student’s marks?(Y/N)>> ")
	if proceed.upper() != "Y":
		items.append( [studentID, finalGrade] )
        print(items)
		print("Program has terminated, goodbye!")
break;
Update: I run this code on Jupyter and it worked, however, I got this result:

Welcome to the Marks Calculator!
Enter Student ID >> 20481792
Enter Assessable Tutorial mark (/10) >> 8
Enter Assignment mark (/100) >> 78
Enter Exam mark (/150) >> 78
Would you like to process another student’s marks?(Y/N)>> y
Enter Student ID >> 205876543
Enter Assessable Tutorial mark (/10) >> 6
Enter Assignment mark (/100) >> 78
Enter Exam mark (/150) >> 121
Would you like to process another student’s marks?(Y/N)>> n
[[205876543, 77.46666666666667]]
Program has terminated, goodbye!

The program just printed out the last value that were introduced.
Reply
#12
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.
Reply
#13
>>> 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!
>>>
Reply
#14
(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.

Thank you so much deanhystad!

I really appreciate your help!

Kind regards,

Azure

(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!
>>>

Thank you so much!!

Kind regards,

Azure
Reply
#15
(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
Reply
#16
The statements with the same indentation belong to the same group similar to blocks created in other programming language using {}

break is part of for loop due to indentation. Hence it print first row and breaks. It should have same indention as "if".
    if proceed.upper() != "Y":
 
        for studentID, finalGrade in items:
            print(studentID, finalGrade)
            print("Program has terminated, goodbye!")
            break;
Same issue in your implementation of deanhystad's code
Reply
#17
(Apr-26-2020, 10:58 AM)anbu23 Wrote: The statements with the same indentation belong to the same group similar to blocks created in other programming language using {}

break is part of for loop due to indentation. Hence it print first row and breaks. It should have same indention as "if".
    if proceed.upper() != "Y":
 
        for studentID, finalGrade in items:
            print(studentID, finalGrade)
            print("Program has terminated, goodbye!")
            break;
Same issue in your implementation of deanhystad's code

Thank you so much anbu23!

Kind regards,

Azure
Reply


Forum Jump:

User Panel Messages

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