0

I'm trying to create the basic question for my blackjack game and I want to pass the user's input as a parameter inside a function I created. I tried running my code inside my terminal and nothing happened. Can someone tell me what I did wrong?

#function that passes one parameter that prints a question

def ask_user(a):
    print('Would you like to HIT or STAND?')

#variable that holds the user's input

user_answer = input()

#calling the function and passing the users input as the parameter

ask_user(user_answer)
2
  • 1
    Your indentation is wrong, plus your function returns nothing. Commented Sep 17, 2017 at 17:44
  • I think you're looking for def ask_user(a): user_answer = input('Would you like to HIT or STAND?'). Commented Sep 17, 2017 at 17:49

4 Answers 4

1

Terminal is waiting for input from you. this will make it clear:

#function that passes one parameter that prints a question
def ask_user(a):
     print('Would you like to HIT or STAND?')

#variable that holds the users input
user_answer = input("type user input here: ")

#calling the function and passing the users input as the parameter
ask_user(user_answer)

From your comment, consider this:

def ask_user():
    user_answer = input("Would you like to HIT or STAND? ")
    print("the users reply is stored in user_answer. And is",user_answer )
ask_user()
Sign up to request clarification or add additional context in comments.

2 Comments

Sweet, I get that part. Except how could I write it so that it will ask "HIT or STAND" then store that value as a variable but put it inside a function?
your input is already stored in a value which you passed in parameter as 'a'. You can add, then to your function: if a == 'Hit': #do something
0

You mean you just want to pass a variable into the function and have it printed as well as another print statement?

def ask_user(a):
    print('Would you like to HIT or STAND?')
    print(a) #if you just want it to print your variable 'a'
    return a   # if you want your function to return your input

def ask_user(a):
    print('Would you like to HIT or STAND?')
    return a   # if you want your function to return your input

def ask_user(a):
    print('Would you like to HIT or STAND?: ', a) # prints both on 1 line

Comments

0

I would suggest you to do something like this:

def ask_user():
    print("Would you like to HIT or STAND?")
    return (input("type use input here: "))

my_var=ask_user()

print ("You decided to", my_var)

Comments

0

my approach would be something like this, hope this helps

def ask_user(a):
        print('Would you like to HIT or STAND?')
        user_answer = input()
        if(user_answer=="HIT"):
              #some code or function call with parameter "HIT"
        elif(user_answer=="STAND"):
              #some code or function call with parameter "STAND"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.