The if statement:
The if statement is used to check a certain condition. if the condition is true, we run a block of statements, else we process another block of statements.
x = int(input("Please enter your age:"))
if x<=30:
print("You are still young!")
else:
print("You are getting older")
if x<=30:
print("You are still young!")
else:
print("You are getting older")
Another Example,
x = int(input("Please enter your age:"))
if 0<x<30:
print("You are still young!")
elif x<0:
print("Sorry. Your age cant be Negative!")
elif x==0:
print("Your are Just Born!! Congratulation.")
elif x==100:
print("Congratulation for being 100 years of old")
elif x>100:
print("Cool!")
else:
print("You are getting older")
if 0<x<30:
print("You are still young!")
elif x<0:
print("Sorry. Your age cant be Negative!")
elif x==0:
print("Your are Just Born!! Congratulation.")
elif x==100:
print("Congratulation for being 100 years of old")
elif x>100:
print("Cool!")
else:
print("You are getting older")
Simple for Statement:
The for statement in Python differs a bit from what you may be used to in C or Pascal.
Python has built in factorial function. ie.
import math
for i in range(11):
print(math.factorial(i))
for i in range(11):
print(math.factorial(i))