How To Use "if input = whatever" statements in python
so i started a few days ago and i cant find anything on how to use if statements other than with numbers, and just to clarify im trying to use it in a text adventure stance for my dads birthday (hes a coder)
phrase = input('Put a phrase: ') if phrase == "hey": print("HI!")
That is just a simple example. But that would be how you do it.
input built-in function in Python, you can put any string inside of it and it will print it out then expect input afterwards.
The value of the input is then stored in the variable name. You can then use the variable name to check the value!
so here's a basic program that determines if what the user says is equal to something:
name = input("Enter your name! ") # asks user for their name # conditionals if name == "Bob": # if what the user wrote equals "Bob" print("Hi bob!") # remember indentation elif name == "Dan": # if what the user wrote equals "Bob" print("Hi Dan!") else: # if any of the previous conditionals are false print("Who are you?")
Lemme know if I was unclear or if you need more help! :)