When I run the program it ignores any opportunity for the user to enter a response.

+1 vote
asked Oct 18 by anonymous
'''

                            Online Python Compiler.
                Code, Compile, Run and Debug python program online.
Write your code in this editor and press "Run" button to execute it.

'''
import random
print("Would you like to play a game? Y/N")
answer = input
if answer == 'Y':
    main(
            (
                print('''You are playing the game with Ralph.
                He holds up his hand, in a fist.
                He then sticks out his thumb
                Ralph: This is monkey
                He then sticks out his pointer finger, two of his fingers out
                Ralph: This is one
                He sticks out his middle finger, three of his fingers out
                Ralph: This is two
                He sticks out his ring finger, four of his fingers out
                Ralph: This is three
                He sticks out his pinky, all of his fingers out
                Ralph: This is 4''')
                
                
                )
        (
        print("please come play again")  
        )
        
)

1 Answer

0 votes
answered Oct 21 by (2,230 points)

Okay. First thing is that you use input incorrectly. In python input is a function so instead of

answer = input

you should do

answer = input()

and since you want to print a question to the player you might as well do

answer = input("Would you like to play a game? Y/N")

which will do the same thing as you intended it to. Also - importing random is unnecessary in your code.

Second thing is I don't understand what you wanted to do with this main function. If you wanted a main fuction as in C or C++ for example then you should know that in python this is not needed. Although in some cases (like writing modules) you might want to do

if __name__ == "__main__":

    main()

while having your main function defined before this or every instruction you want to be executed be placed inside that if statement.

In case this wasn't what you intended then your revised code should look like this

def play():
    print('''You are playing the game with Ralph.
He holds up his hand, in a fist.
He then sticks out his thumb
Ralph: This is monkey
He then sticks out his pointer finger, two of his fingers out
Ralph: This is one
He sticks out his middle finger, three of his fingers out
Ralph: This is two
He sticks out his ring finger, four of his fingers out
Ralph: This is three
He sticks out his pinky, all of his fingers out
Ralph: This is 4''')
    print("please come play again")

answer = input("Would you like to play a game? Y/N \n")
if answer == 'Y':
    play()

or this

answer = input("Would you like to play a game? Y/N \n")
 

if answer == 'Y':
    print('''\nYou are playing the game with Ralph.
He holds up his hand, in a fist.
He then sticks out his thumb
Ralph: This is monkey
He then sticks out his pointer finger, two of his fingers out
Ralph: This is one
He sticks out his middle finger, three of his fingers out
Ralph: This is two
He sticks out his ring finger, four of his fingers out
Ralph: This is three
He sticks out his pinky, all of his fingers out
Ralph: This is 4''')
    print("\nplease come play again")

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...