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

Lab 3 Practice

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

Lab 3 Practice

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

Lab 3-4 Practice

#1. Syntax of if statement


"""if test_expression:
statement 1
.......
statement x """

#2. Check which no is greater

a = 30
b = 207
if b > a:
print("b is greater than a") # you will get an error

#3. program to increment the number if it is positive


x=int(input("Enter the no "))
if(x>0):
x=x+1 # Statement
print(x )

# 4 program to determine whether a person is eligible to vote


x=int(input("Enter the age "))
if(x >=18):
print(" eligible to vote") # statement 1

#5 Syntax of if else statement


"""if test_expression:
statement 1
.......
else:
statement 2
statement x """

# 6 .program to determine whether a person is eligible to vote.


# If he is not eligible ,display how many years are left to be eligible

x=int(input("Enter the age "))

if(x >=18):
print(" eligible to vote")
else:
b= 18-x
print(" not eligible to vote.you have to wait for " ,b )
#7.program to determine whether a numbers are equal or not.

a = 33
b = 33
if b > a:
print("b is greater than a")
elif a == b:
print("a and b are equal")

# 8 write a program to find larger of 2 nos


a=int(input("enter the value of a: "))
b=int(input("enter the value of b: "))
if(a>b):
print(a, " is the largest no")
else :
print(b,"is the largest no")

#9 write a program to find whether the given no is even or odd


n =int(input("enter any number: "))
if(n%2==0):
print(n, " is even")
else:
print(n,"is odd")

#10 write a program to find whether a given no is a leap year or not


year=int(input("enter any year "))
if(year%4==0 and year %100!=0) or (year%400==0): # f t== t
print("leap year")
else:
print("not a leap year")

#11 Ladder if
#Program to enter a number and print its interval (0-10, 10-20, 20-
30, 30-40, 40-50)

x=int(input("enter any number between 0-50 "))


if(x>=0 and x<10):
print("it is in the range of 0-10")
if(x>=10 and x<20):
print("it is in the range of 10-20")
if(x>=20 and x< 30):
print("it is in the range of 20-30")
if(x>=30 and x< 40):
print("it is the range of 30-40")
if(x>=40 and x< 50):
print("it is the range of 40-50")

#print("invalid number")
#12 Ladder if
#Program to enter a number and print its interval

x=int(input("enter any number between 0-50 "))

if(x>=0 and x<10):


print("it is in the range of 0-10")
elif(x>=10 and x<20):
print("it is in the range of 10-20")
elif(x>=20 and x< 30):
print("it is in the range of 20-30")
elif(x>=30 and x< 40):
print("it is the range of 30-40")
elif(x>=40 and x< 50):
print("it is the range of 40-50")
else:
print("invalid choice")

# 13
""" marks 90-100------------A+
80-90 A
70-80 B
60-70 C
less than 60 D" more efffort required""""

#14 program to find a number is +ve, -


ve or equal to zero num=0, num>0, num<0
num=int(input("enter any number "))
if(num==0):
print("the value is equal to zero")
elif(num>0): #else+if= elif
print("the value is positive")
else: #num<0
print(" the value is negative")

#15. ladder if (0,+ve, -ve)

num=int(input("enter any number "))

if(num==0):
print("the value is equal to zero")

if(num>0):
print("the value is positive")

if(num<0):
print("the value is -ve")

# 16 Nested if else----- If (if -else ) Else(if -


else) 4 (if elif elif else)( if if if if )(if (if else) else(if else)

num=int(input("enter any number "))

if(num>=0):
if(num==0):
print("the value is equal to zero")
else: #num>0
print("the value is positive")

else: # num<0
print("the value is -ve")

#17. Write a program to Accept two Integers and Check if they are Equal
.
num1=int(input("enter any number "))
num2=int(input("enter any number "))
if(num1==num2):
print("Both are equal")

#18 write a program to find the greatest of 3 nos( Nested if else)


num1=int(input("enter any number "))
num2=int(input("enter any number "))
num3=int(input("enter any number "))
if(num1>num2):
if(num1>num3):
print(num1,"is greatest")
else: #num3>num1
print(num3,"is greatest")
else: #num2>num1
if(num2>num3):
print(num2,"is greatest")
else:
print(num3, "is greatest")

#19 write a program to find the greatest of 3 nos( else if)


num1=int(input("enter any number "))
num2=int(input("enter any number "))
num3=int(input("enter any number "))
if(num1> num2 and num1>num3):
print(num1 ," is the greatest")
elif(num2>num1 and num2>num3):
print("the largest no is", num2)
else: #num3>num1 and num3>num2
print("the largest no is", num3)

#19. Write a program to Add/subtract two Complex Numbers.

z1 = complex(2, 3)
x=int(input("Enter the real value"))
y=int(input("Enter the imaginary value"))
z2 = complex(x,y)
z3=z1+z2
print( "Addition is : ", z3)
z4=z1-z2
print("Subtraction:", z4)

#20.Write a program to print color name, if user enters the first lette
r of the color name.
n=(input("enter first character of color "))
#if elif else
if(n=="r" or n=='R'):
print("Red")
elif(n=="B" or n=='b'):
print("Blue/Black/Brown")
elif(n=="y" or n=='Y'):
print("Yellow")
elif(n=="p" or n=='P'):
print("Pink/Purple")
elif(n=="o" or n=='O'):
print("Orange")
elif(n=="w" or n=='W'):
print("White")

else:
print("invalid color")

#Perform arithmetic operations using if else block

print("Select operation.")

print("1.Add")
print("2.Subtract")
print("3.Multiply")
print("4.Divide")

choice = input("Enter choice(1/2/3/4): ")


# check if choice is one of the four options
if choice in ('1', '2', '3', '4'):
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
if choice == '1':
a=num1+num2
print("addition is :",a)
elif choice == '2':
s=num1-num2
print("Subtraction is :",s)
elif choice == '3':
m=num1*num2
print("Multiplication is :",m)
elif choice == '4':
d=num1/num2
print("Division is :",d)

else:
print("Invalid Input")

64. Write a menu driven program for calculating area of different geom
etrical figures such as circle, square, rectangle, and triangle.

print("Calculate Shape Area")


shape_name = input("Enter the name of shape whose area you want to find
:(rectangle/square/triangle/circle/parallelogram) ")

name = shape_name.lower()

# check for the conditions


if name == "rectangle":
l = int(input("Enter rectangle's length: "))
b = int(input("Enter rectangle's breadth: "))
rect_area = l * b
print("The area of rectangle is ",rect_area)

elif name == "square":


s = int(input("Enter square's side length: "))
sqt_area = s * s
print("The area of square is",sqt_area)

elif name == "triangle":


h = int(input("Enter triangle's height length: "))
b = int(input("Enter triangle's breadth length: "))
tri_area = 0.5 * b * h

print("The area of tiangle is",tri_area)


elif name == "circle":
r = int(input("Enter circle's radius length: "))
pi = 3.14
circ_area = pi * r * r
print("The area of circle is",circ_area)

elif name == 'parallelogram':


b = int(input("Enter parallelogram's base length: "))
h = int(input("Enter parallelogram's height length: "))
para_area = b * h
print("the area of llgm is ",para_area)

else:
print("Sorry! This shape is not available")

You might also like