technical skills grow

Responsive Ads Here

Sunday, July 25, 2021

PYTHON EXERCISES FOR IF ELSE

 Q1:

a = 10
b = "This is python"
c = 10.5

print(type(a))
print(type(b))
print(type(c))
Output 
<class 'int'>
<class 'str'>
<class 'float'>

Q2:

print("Please enter the first no ")
no1 = input()
print("Please enter the second no ")
no2 = input()
def add():
print("Sum of two no :-", int(no1) + int(no2))

def mul():
print("Multiple of two no", int(no1) * int(no2))
add()
mul()
OUTPUT:
Please enter the first no 
10
Please enter the second no
30
Sum of two no :- 40
Multiple of two no 300

Q3 :Use max | min | reverse | append | insert

list1 = [1,10,20,43,3, 4, 5, 7, 8]
list1.sort()
print("print list sort item:" , list1)

list1.reverse()
print("print reverse list item:", list1)
print("max item:", max(list1))
print("min item:", min(list1))
list1.append(50)
list1.append(501)
print("add item:", list1)
list1.remove(8)
print("print list item:", list1)
list1.insert(1,100)
print("print list item:", list1)

Output
print list sort item: [1, 3, 4, 5, 7, 8, 10, 20, 43]
print reverse list item: [43, 20, 10, 8, 7, 5, 4, 3, 1]
max item: 43
min item: 1
add item: [43, 20, 10, 8, 7, 5, 4, 3, 1, 50, 501]
print list item: [43, 20, 10, 7, 5, 4, 3, 1, 50, 501]
print list item: [43, 100, 20, 10, 7, 5, 4, 3, 1, 50, 501]

Q5: Check Odd and Even no

no = int(input("Enter the no"))
if no % 2 == 0:
print("Even'")
else:
print("ODD")

Enter the no3
ODD

Program to print the largest of the three numbers

 no1 = int(input("Enter the first :-"))
no2 = int(input("Enter the second :-"))
no3 = int(input("Enter the third :-"))

if no1 > no2 and no1 > no3:
print("no1 is bigger then all :", no1)
if no2 > no3 and no2 > no1:
print("no2 is bigger then all :", no2)
if no3 > no1 and no3 > no2:
print("no3 is bigger then all :", no3)
Output :
Enter the first :-10
Enter the second :-20
Enter the third :-30
no3 is bigger then all : 30


Program to check whether a number is even or not.

a = int(input("Enter the no :-"))
if a % 2 == 0:
print(a, 'is even no');
else:
print(a, 'is not even no');
Output :
Enter the no :-30
30 is even no

Write a program to check scored

marks = int(input("Enter the Marks :-"))
if marks > 85 and marks <= 100:
print("Your scored A Grade");
elif marks > 60 and marks <= 85:
print("Your Scored B Grade");
elif marks > 40 and marks <= 60:
print("Your Scored C Grade");
elif marks >= 101:
print(marks,"more then marks is not exist ")
else:
print("Failed");
Output :
Enter the Marks :-90
Your scored A Grade
 

No comments:

Post a Comment

Powered by Blogger.

Labels

Contact Form

Name

Email *

Message *

Search This Blog

Blog Archive

Ad Code

Responsive Advertisement

Recent Posts