So I am making the menu for a rock paper scissors game, and it's working other than the quit function in the main menu.
I know that it's because the blank space used for enter is considered a string, but the assignment requires that I use enter to quit from the main menu. Can someone show me the operation I am missing that tells IDLE to take a string as input? or how to possibly convert it from a string to an int?
Here's my code:

def menuMain():
    print("--------------------------------------------------------")
    print(" Welcome to the wonderful world of Paper Rock Scissors! ")
    print("--------------------------------------------------------\n")
    print(" 1) One Player Game ( One human playing against the computer.) \n")
    print(" 2) Enter for a Two Player Game ( Two humans playing against each other.) \n")
    print(" Choose game type or press ENTER to quit game. \n")
    print("-----------------------------------------------")
    menuChoice = eval(input(" Please enter a choice from the above menu: \n-----------------------------------------------\n"))


    if (menuChoice == 1):

        print(" You have decided to play a one player game against the computer. \n")
        print(" 1) Paper \n")
        print(" 2) Rock \n")
        print(" 3) Scissors \n")
        print(" 4) Quit \n")
        subMenuChoice = eval(input( "Please choose from the above weapons menu: \n"))
        if( subMenuChoice == 1):
            print(" You have chosen Paper. ")
        elif(subMenuChoice == 2):
            print(" You have chosen Rock. ")
        elif(subMenuChoice == 3):
            print(" You have chosen Scissors. ")
        elif(subMenuChoice == 4):
            print(" You have chosen to quit. ")
            return 0
        else:
            print(" Invalid menu choice. ")

    elif (menuChoice == 2):
        print (" You have decided to play a two player game against another human. ")
        print(" 1) Paper \n")
        print(" 2) Rock \n")
        print(" 3) Scissors \n")
        print(" 4) Quit \n")
        subMenuChoice = eval(input(" Please choose from the above weapons menu: \n"))
        if( subMenuChoice == 1):
            print(" You have chosen Paper. ")
        elif(subMenuChoice == 2):
            print(" You have chosen Rock. ")
        elif(subMenuChoice == 3):
            print(" You have chosen Scissors. ")
        elif(subMenuChoice == 4):
            print(" You have chosen to quit. ")
            return 0
        else:
            print(" Invalid menu choice. ")
    elif (menuChoice == ""):
        print (" Quitting game. Thank you for playing, please play again soon. ")
        return 0
    else:
        print(" Invalid menu choice. ")

menuMain()

Please just help me with this part...I'm not interested in hearing how I can shorten everything up, I'm trying to build this from the ground up first.
Thanks

Recommended Answers

All 4 Replies

Okay so, as I've heard it happens so many times, I walked away for a bit and it hit me while giving my son a bath...I changed the input to just input, and used the numbers as strings in my if else statements. I'll post my code for reference:

def menuMain():
    print("--------------------------------------------------------")
    print(" Welcome to the wonderful world of Paper Rock Scissors! ")
    print("--------------------------------------------------------\n")
    print(" 1) One Player Game ( One human playing against the computer.) \n")
    print(" 2) Enter for a Two Player Game ( Two humans playing against each other.) \n")
    print(" Choose game type or press ENTER to quit game. \n")
    print("-----------------------------------------------")
    menuChoice = (input(" Please enter a choice from the above menu: \n-----------------------------------------------\n"))


    if (menuChoice == "1"):

        print(" You have decided to play a one player game against the computer. \n")
        print(" 1) Paper \n")
        print(" 2) Rock \n")
        print(" 3) Scissors \n")
        print(" 4) Quit \n")
        subMenuChoice = eval(input( "Please choose from the above weapons menu: \n"))
        if( subMenuChoice == 1):
            print(" You have chosen Paper. ")
        elif(subMenuChoice == 2):
            print(" You have chosen Rock. ")
        elif(subMenuChoice == 3):
            print(" You have chosen Scissors. ")
        elif(subMenuChoice == 4):
            print(" You have chosen to quit. ")
            return 0
        else:
            print(" Invalid menu choice. ")

    elif (menuChoice == "2"):
        print (" You have decided to play a two player game against another human. ")
        print(" 1) Paper \n")
        print(" 2) Rock \n")
        print(" 3) Scissors \n")
        print(" 4) Quit \n")
        subMenuChoice = eval(input(" Please choose from the above weapons menu: \n"))
        if( subMenuChoice == 1):
            print(" You have chosen Paper. ")
        elif(subMenuChoice == 2):
            print(" You have chosen Rock. ")
        elif(subMenuChoice == 3):
            print(" You have chosen Scissors. ")
        elif(subMenuChoice == 4):
            print(" You have chosen to quit. ")
            return 0
        else:
            print(" Invalid menu choice. ")
    elif (menuChoice == ""):
        print (" Quitting game. Thank you for playing, please play again soon. ")
        return 0
    else:
        print(" Invalid menu choice. ")

menuMain()

If anyone would still like to tell me if it's possible to make Python accept a string as eval input, I would love to know...Thanks

do you mean like this:

def main():
    menu = raw_input("choose rock, paper, or scissors: ")
    if menu == "rock":
        print "Rock"
    elif menu == "paper":
        print "Paper"
    elif menu == "scissors":
        print "Scissors"
    else:
        print "Invalid selection"

main()

this would allow you to check string

I would also build in some error handling and user input handling such as have it set the raw_input given to .lowercase or .uppercase to ensure that if the user types Rock it will be treated the same as rock or rOCk for instance

In Python3 the input() function returns a string.
If you want an integer you use int(input()).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.