xxxxxxxxxx
if foo == 'abc' and bar == 'bac' or zoo == '123':
# do something
xxxxxxxxxx
if num<5:
print('Num less than 5')
elif 5<= num <=9:
print('Num between 5 and 9')
else:
print('Num more than 9')
xxxxxxxxxx
# if statment
#'if' gives condition in statement to make program more efficient.
a=10
b=5
if a%b==0:
print('true')
output:
true
xxxxxxxxxx
weather == "Good!" or weather == "Great!":
# Or the following
weather in ("Good!", "Great!"):
xxxxxxxxxx
def e(x):
if x == "Sunny" and x == "sunny":
print('Remember your sunglasses!')
elif x == "Rainy" and x == "rainy":
print('Do not forget your umbrella!')
elif x == 'Thunderstorm' or x == 'thunderstorm' or x =='Stormy' or x == 'stormy':
print('Stay Home!')
x = input('What is the weather?')
xxxxxxxxxx
Num1=float
Num2=float
Ans=float
operator=int
print("These are the following operations available:\n, 1 for addition.\n 2 for subtraction.\n 3 for multiplication.\n 4 for division.")
operator = int(input("Enter the operator you wish to use"))
Num1 = float(input("Please enter your first number:"))
Num2 = float(input("Please enter your second number:"))
if operator ==1:
Ans == Num1 + Num2
else:
if operator ==2:
Ans == Num1 - Num2
else:
if operator ==3:
Ans == Num1 * Num2
else:
if operator ==4:
Ans == Num1 / Num2
print("Your answer is: %f.2", Ans)
xxxxxxxxxx
#if using or / and
name='ron'
town='Tel Aviv'
age=25
if age>18 and town=='Tel Aviv':
print(f'Name is {name} Age {age} and town is {town}\nusing and')
else:
print('other')
#answer is: Name is Ron Age 25 and town is Tel Aviv
using and
xxxxxxxxxx
person = input("Nationality? ")
if person == "french" or person == "French":
print("Préférez-vous parler français?")
if person == "italian" or person == "Italian":
print("Preferisci parlare italiano?")