Flow of Control practical live
Flow of Control practical live
Enter a side:10
Perimeter of square: 40
Enter a side:10
Area of square: 100
Enter a side:2
Area of square: 4
if statement
In [1]: age=int(input("Enter your age:"))
if age>=18:
print("Yes u can vote...!!")
if else statement
In [11]: age=int(input("Enter your age:"))
if age>=18:
print("Yes u can vote...!!")
else:
print("Sorry...You cannot vote!!!!")
Enter sale:55000
Bonus is: 5500.0
55000
if with elif
WAP in python to provide grade to student as per following criteria
marks is greater than 90---Grade A marks is greater than 75 and less than equal to 90---
Grade B Marks is less than 75 and greater than or equal to 60--- Grade C Marks is less than
60 G d D
In [10]: marks=float(input("Enter your marks:"))
if marks>90:
print("Grade is A")
elif marks>=75:
print("Grade is B")
elif marks>=60:
print("Grade is C")
else:
print("Grade is D")
Enter a number:10
10 is an even number
HW
WAP to find whether a number is divisible by 5 or
not
In [2]: num=int(input("enter your number"))
if num%5==0:
print(num,"is divisible by 5")
else:
print(num,"is not divisible by 5 ")
enter number7
7 yes number you entered is divisible by 7
enter number89
89 yes number you entered is not divisible by 7
In [5]: num=int(input("enter your number:"))
if num%3==0:
print(num,"is divisible by 3")
else:
print(num,"is not divisible by 3")
nested if
In [6]: age=int(input("Enter age:"))
gender=input("Enter your gender:")
if gender=="Male":
if age>=18:
print("He can vote")
else:
print("He cannot vote")
elif gender=="Female":
if age>=18:
print("She can vote")
else:
print("She cannot vote")
else:
print("Please enter correct Gender (Male/Female)")
Enter age:12
Enter your gender:female
Please enter correct Gender (Male/Female)
In [9]: age=int(input("Enter age:"))
gender=input("Enter your gender:")
if gender=="Male":
if age>=18:
print("He can vote")
else:
print("He cannot vote")
else:
if age>=18:
print("She can vote")
else:
print("She cannot vote")
Enter age:13
Enter your gender:cant say
She cannot vote
Enter a number:23
Number is odd