← Back to Community
How do you use the 'if' function in Python?
Profile icon
Intellect103

How do you use the 'if' function in Python?

I have tried and researched but I was unable to find the right thing to do . I hope anyone can help me. Thanks!!!

Voters
Profile icon
ZaneVandenBoom
Profile icon
SirBilby
Profile icon
Intellect103
Comments
hotnewtop
Profile icon
[deleted]

Its very easy.

print("1+1=?") ans = intput("> ") if ans == "2": print("Goed")
Profile icon
MisterMr

@Intellect103
i made my own version of the code. :P

https://replit.com/@MisterMr/Hello#main.py

Profile icon
OldWizard209

How do you use the 'if' function in Python?

The if function ????. I think you meant if statements. Functions are not the same as statements. The if statement is conditional. It means that if the statement you have provided evaluates to true, it will run the code in its code block. The elif runs only if the first if doesn't work. The else statements handles all exceptions and runs the specified code"

age = 16 if age >= 18: print("You are old enough") elif age < 18: print("You are not old enough") else: print("You are nothing")
Profile icon
Intellect103

Ok Thanks... @OldWizard209

Profile icon
SirBilby

Here you go:

How to improve the code where an if statement is needed:

print("Answer with yes or no") sad = input("Do you think it is weird? ") if sad == "yes" print("Oh, thank you.") elif sad == "no" print(name + "that is mean!")
Profile icon
SirBilby