0% found this document useful (0 votes)
11 views4 pages

Python Assignment 4 if Elif Else

Uploaded by

Shubham Chaubey
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
11 views4 pages

Python Assignment 4 if Elif Else

Uploaded by

Shubham Chaubey
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 4

31/07/2024, 09:25 Python Assignment_4_If_elif_else

In [2]: # wap ask the user enter a number


# find it is a even number or odd number
# idea: any number divide by 2 , the remiander=0
# it is called as even number

number = eval(input('Enter a number :'))


if number % 2 ==0 :
print (f'{number} Number is evan')

else:
print(f'{number} Number is odd')

5 Number is odd

In [3]: # Implement the above problem by taking a random input between 1, 100

import random
number = random.randint(1,100)
if number % 2 ==0 :
print (f'{number} Number is evan')

else:
print(f'{number} Number is odd')

46 Number is evan

In [4]: # wap ask the user enter the distance


# if distance greater than 25km
# then enter the charge
# print the total cost
#otherwise
# print free ride

distance =eval(input('enter distance :'))


amount = eval(input('enter amount :'))

if distance >= 26:


price = (distance-25)*amount
print(f'total distance is {distance} km and price is {price} Rs.')

else:
print('Free no cost')

Free no cost

In [5]: # wap ask the user enter the distance


# cutoff distance enter 25
# if distance greater than 25km
# print("good news your charge is aplicable for only remaining of 25")
# chargeble distance= distance-cutoff
# then enter the charge
# print the total cost
#otherwise
# print free ride

distance =eval(input('enter distance :'))


if distance <= 25:
print('"good news your charge is aplicable for only remaining of 25"')

file:///C:/Users/Shubham/Downloads/Python Assignment_4_If_elif_else.html 1/4


31/07/2024, 09:25 Python Assignment_4_If_elif_else

else:
charge=eval(input('enter charge :'))
total = distance*charge
print(f'total charge {total} Rs. of distance {distance}')

"good news your charge is aplicable for only remaining of 25"

In [7]: # wap ask the user enter the course


# ask the user enter the Institute
# if the course equal to data science and institute equal to naresh it
# then you are good
# otherwise
# you are bad

course = str(input('Enter Course name : '))


institute = str(input('Enter Institute name : '))

if course== 'Data science' and institute == 'NareshIt':


print('you are good')

else :
print('you are bad')

you are good

In [8]: # wap ask the user enter a random number between 1 to 10, treat this as number1
# ask the user enter another number from keyboard, treat this as number2
# if number1 equal to number2
# print you won
# otherwise
# print you lost

number = random.randint(1,10)
num1=eval(input('Enter a number1 :'))

if number == num1:
print (f'Random number :{number}, You enter : {num1} and you Won')

else:
print('Loss')

Loss

In [10]: # wap ask the user enter number


# if number equal to 1 then print one
# if number equal to 2 then print two
# if number equal to 3 then print three
# otherwise print enter a valid number

num = eval(input('Enter a number :'))


if num == 1:
print('number is one')

elif num==2:
print('number is two')

elif num==3:
print('number is three')

else:
print(f'number is {num}')

file:///C:/Users/Shubham/Downloads/Python Assignment_4_If_elif_else.html 2/4


31/07/2024, 09:25 Python Assignment_4_If_elif_else

number is 4

In [12]: # wap ask the user enter a number


# if that number greater than zero print postive
# if that number less than zero print negative
# otherwise print zero

num = eval(input('Enter the number :'))


if num >= 0:
if num ==0:
print('Zero')
else:
print('Positive number')

else :
print('negative number')

negative number

In [14]: # WAP ask the user enter the percentage of marks 0 to 100
# if percentagw gretaer than 90 print A garde
# if percentage between 75 to 90 print B garde
# if percentage between 50 to 75 print C grade
# if percentage between 35 to 50 print D grade
# if percentage less than 35 print Fail

percentage = eval(input('Enter a Percentage :'))

if percentage >= 90:


print('You got A garde')

elif percentage >= 75 :


print('You got B garde')

elif percentage >= 50 :


print('You got C garde')

elif percentage >= 35 :


print('You got D garde')

else:
print('fail')

You got D garde

In [16]: # WAP ask the user enter the age


# if the age greater tahn 100 print you are lucky
# if the age gretaer than 75 print old age
# if the age between 50 to 75 print ss
# if the age between 30 tp 50 print MA
# if the age between 15 to 30 print young age
# if the afe between less than 15 print kid

age = eval(input('Enter your age :'))


if age>100:
print('You are lucky')

elif age>= 70 :
print('You old age')

file:///C:/Users/Shubham/Downloads/Python Assignment_4_If_elif_else.html 3/4


31/07/2024, 09:25 Python Assignment_4_If_elif_else

elif age>= 50 :
print('You are ss')

elif age>= 30 :
print('You are MA')

elif age>= 15 :
print('You are young age')

else:
print('Teenage')

Teenage

In [ ]:

file:///C:/Users/Shubham/Downloads/Python Assignment_4_If_elif_else.html 4/4

You might also like