0
score = []
percent = []
add = []

print("Enter Grade") 

#getting input from user
def multi_input():
    try:
        while True:
            data=input()
            if not data: break
            yield data
    except KeyboardInterrupt:
        return

data = list(multi_input())

#filter data into percent and score
for i in range(3, len(data),4):
    data[i] = data[i].split('\t')
    try:
        percent.append(data[i][3])
        score.append(data[i][4])
    except IndexError:
        result = 0

#take out ungraded values
percent = [value for value in percent if value != '']
score = [value for value in score if value != '']

#refine percent data
for i in range(len(percent)):
    try:
        percent[i] = percent[i].replace('%', '')
        percent[i] = float(percent[i])
    except ZeroDivisionError:
        result = 0

#refine score data
for i in range(len(score)):
    score[i] = score[i].split('/')
    for j in range(len(score[i])):
        score[i][j] = float(score[i][j])
    try:
        score[i] = score[i][0]/score[i][1]*100
    except ZeroDivisionError:
        result = 0

#amount of assignments
print()
print("graded assignments: ", len(score))

#calculation
for i in range(len(score)):
    add.append(score[i]*percent[i]/100)

print(f"{sum(add)/sum(percent)*100:05.2f}")

This code should print the GPA of this input/data after pressing enter two times:

Oct 12
Tests Test 2 B 18.3% 41/50 10/12/22 Oct 05
Labs & Projects Plant Pigments A 15% 9/10 10/7/22 Sep 28
Homework/Assignments Leaf Anatomy A 2.6% 20/20 9/28/22 Sep 23
Homework/Assignments Osmosis A 3.4% 26/26 10/21/22 Sep 21
Tests Test 1 B 21.7% 47.5/59 9/23/22 Sep 21
Homework/Assignments Cell Diagrams A 2.6% 20/20 9/28/22 Sep 07
Labs & Projects Lab: Identifying Macromolecules A 15% 12/10 9/21/22 Sep 07
Homework/Assignments Properties of Water A 4% 30/30 9/14/22 Sep 05
Homework/Assignments Enzymes: Practice What You Know A 2% 15/15 9/14/22 Aug 26
Homework/Assignments Macromolecules Chart A 2.6% 20/20 9/11/22 Aug 22
Homework/Assignments Scientific Investment Practice B 2.6% 16/20 9/13/22

It works perfectly on Pycharm, but when converted to .exe by pyinstaller or autopytoexe, the console screen just closes instead of printing the result.

HELP

I have no idea of where this error comes from since in some platform it works while others do not

Stefan Wuebbe
  • 2,109
  • 5
  • 17
  • 28
  • 1
    "closes instead of printing the result" - more likely, it prints the result very quickly and then exits because it has nothing more to do. You can insert `input()` at the end of your script to make your code wait for the user to input something and terminate the program. – ForceBru Nov 01 '22 at 15:05

1 Answers1

0

The .exe file runs your script, but after it runs it, nothing tells it to keep the window open, so it closes it.

You can try as a very quick solution to add

k = input("press close to exit")

at the end of your script to prompt for input so it doesn't close.

See this or this

Matthias
  • 3,160
  • 2
  • 24
  • 38