'Using global variables in a Python menu-driven program - Intro to Python

I am stuck on the following program. My assignment is to create a menu-driven Python program that asks for user input and performs actions on the numbers based on the menu selection. We are encouraged to use global variables in this somehow. I think that's where I'm having problems. I noted the place where the Python interpreter is getting caught. It's a syntax error, but I can't figure out why. I'm wondering about the rest of the program too since I can't get past this spot.

# Constants for menu choices
score_input = 1
sum_and_average = 2
minimum_value = 3
maximum_value = 4
exit = 5

# Create global variables
score1 = 0
score2 = 0
score3 = 0

# The main function
def main ():

    # Declare global variables  
    global score1, score2, score3

    # Establish choice variable to get and hold user's menu choice
    choice = 0

    while choice != exit:
        # Display the menu
        display_menu ()

        # Gets user’s choice
        choice == input(int("Menu Choice ==> "))

        # Perform the selected action
        if choice == score_input:
            score1 = int (input("Enter score 1: ") # STOPS AFTER THIS LINE 
            score2 = int (input("Enter score 2: ")
            score3 = int (input("Enter score 3: ")
    
        elif choice == sum_and_average:
            sum ()
            average ()
        
        elif choice == minimum_value:
            minimum ()
        
        elif choice == maximum_value:
            maximum ()
        
        elif choice == exit:
            print ("Exiting program")
        
        else:
            print ("Error: invalid selection. ")

def display_menu ():
    print ("Functions")
    print ()
    print ("1. Read in 3 numbers (START HERE)")
    print ("2. Display sum and average")
    print ("3. Find minimum value")
    print ("4. Find maximum value")
    print ("5. Exit program")

def score_input (score1, score2, score3):
    score1 = int (input("Enter score 1: ")
    score2 = int (input("Enter score 2: ")
    score3 = int (input("Enter score 3: ")

def sum (score1, score2, score3):
    sum = (score1 + score2 + score3)
    print (“The sum is: “, sum)

def average (score1, score2, score3):
    average = (int(sum) / 3))
    print (“The average is: “, average)

def minimum (score1, score2, score3):
    minimum = min (score1, score2, score3)
    print ("The minimum score is: ", minimum)

def maximum (score1, score2, score3):
    maximum = max (score1, score2, score3)
    print ("The maximum score is: ", maximum)

main ()


Solution 1:[1]

There are a lot of problems wrong with this program. I could fix everything, and explain all the fixes, but what I think you need to do is delete this code and restart from scratch and start running your code way more frequently while developing.

I.E

 if choice == score_input:
        score1 = int (input("Enter score 1: ")) # STOPS AFTER THIS LINE 
        score2 = int (input("Enter score 2: "))
        score3 = int (input("Enter score 3: "))

    elif choice == sum_and_average:
        sum ()
        average ()
    
    elif choice == minimum_value:
        minimum ()
    
    elif choice == maximum_value:
        maximum ()
    
    elif choice == exit:
        print ("Exiting program")
    
    else:
        print ("Error: invalid selection. ")

elif choice == sum_and_average: and every elif after this is invalid (the functions in the elif blocks are invalid), at your level, you should be coding one very small feature, and then testing (running the program). int (input("Enter score 1: ")).

To your original question on why it's stopping at that specific line is due to a missing ). int (input("Enter score 3: ") -> int (input("Enter score 3: "))

Edit: Also pretty odd you have weird quotes in your code print (“The sum is: “, sum)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alex Mortez