0% found this document useful (0 votes)
8 views

Flow of Control practical live

Uploaded by

mrsanketsesai
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Flow of Control practical live

Uploaded by

mrsanketsesai
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

WAP to calculate perimeter of sqaure

In [4]: a=int(input("Enter a side:"))


area=4*a
print("Perimeter of square:",area)

Enter a side:10
Perimeter of square: 40

WAP to calculate of area of sqaure


In [5]: a=int(input("Enter a side:"))
area=a*a
print("Area of square:",area)

Enter a side:10
Area of square: 100

In [6]: a=int(input("Enter a side:"))


area=a*a
print("Area of square:",area)

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...!!")

Enter your age:17

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 your age:17


Sorry...You cannot vote!!!!
In [13]: age=int(input("Enter your age:"))
if age<18 :
print("Sorry...You cannot vote!!!!")
else:
print("Yes u can vote...!!")

Enter your age:18


Yes u can vote...!!

In [4]: sale=int(input("Enter sale:"))


if sale>50000:
bonus=0.10*sale
print("Bonus is:",bonus)
else:
bonus=0
print("Bonus is:",bonus)
print(sale)

Enter sale:55000
Bonus is: 5500.0
55000

WAP in python to print largest of two


numbers
In [6]: num1=int(input("Enter first number:"))
num2=int(input("Enter Second number:"))
if num1>num2:
print(num1,"is largest")
else:
print(num2,"is largest")

Enter first number:20


Enter Second number:100
100 is largest

WAP in python to print largest of three


numbers
In [ ]: num1=int(input("Enter first number:"))
num2=int(input("Enter Second number:"))
num3=int(input("Enter Third number:"))

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 your marks:59.9


Grade is D

WAP to find largest of three numbers


In [11]: num1=int(input("Enter first number:"))
num2=int(input("Enter second number:"))
num3=int(input("Enter third number:"))
if num1>=num2 and num1>=num3:
print(num1,"is largest")
elif num2>=num3 and num2>=num1:
print(num2,"is largest")
elif num3>=num1 and num3>=num2:
print(num3,"is largest")
else:
print("Unable to predict")

Enter first number:91


Enter second number:90
Enter third number:90
91 is largest

WAP to take input temperature of water and


print its physical state
In [16]: temp=float(input("Enter temperature of water:"))
if temp>=100:
print("Water is in Gaseous state")
elif temp<=0:
print("Water is in Solid state")
else:
print("Water is in liquid state")

Enter temperature of water:50


Water is in liquid state
WAP to find whether a number is even or
odd
In [16]: num=int(input("Enter a number:"))
if num%2 ==0:
print(num,"is an even number")
else:
print(num,"is an odd number")

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 your number3


3 is not divisible by 5

WAP to find whether a number is not divisble by 7 or


not
In [3]: num1=int(input("enter number"))
if num1%7==0:
print(num1,"yes number you entered is divisible by 7")
else:
print(num1,"the number entered is not divisible")

enter number7
7 yes number you entered is divisible by 7

In [4]: num1=int(input("enter number"))


if num1%7!=0:
print(num1,"yes number you entered is not divisible by 7")
else:
print(num1,"the number 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")

enter your number:9


9 is divisible by 3

WAP to find whether a triangle is scalene,


isoceles, or equilateral
In [22]: a=int(input("Enter first side:"))
b=int(input("Enter Second side:"))
c=int(input("Enter third side:"))
if a==b and b==c and c==a:
print("It is an equilateral triangle")
elif a==b or b==c or c==a:
print("It is an isoceles triangle")
else:
print("It is a scalene triangle")

Enter first side:9


Enter Second side:10
Enter third side:8
It is a scalene triangle

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

In [1]: number=int(input("Enter a number:"))


if number%2==0:
print("Number is even")
else:
print("Number is odd")

Enter a number:23
Number is odd

You might also like