Ask coding questions

← Back to all posts
Help with if/for/while statements in Python
chainuserbisc (0)

Let's say I do x = "Are you cool?" and then
if x = "yes"
print("Congrats")
Whenever I try something like this I get a syntax error. Can anyone help? Thanks so much.

Answered by cannonthepom123 (14) [earned 5 cycles]
View Answer
Comments
hotnewtop
cannonthepom123 (14)

2 equal signs for if equal
here is better code

print("are you cool?")
x = input("")
if x == "yes" :
 print("you better be")
Bookie0 (5956)

You'll need to use conditionals (if), and an input to get input from the user.

What's the syntax error? Here's a sample piece of code:

x = input("Ask a question ")

if x == "something":
  print("Something") # add rest of code here
IcynDevz (744)

you need to do:

x = "Are you cool?"
if x == "yes":
  print("Congrats")

and also if you want to ask the user are you cool then you need a input statement not defining a variable. So you would do

x = input("Are you cool?")
if x == "yes":
  print("Congrats")
chainuserbisc (0)

@IcynHackz Great thanks for the help.