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

Conditional

Uploaded by

khushbu.shahni13
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

Conditional

Uploaded by

khushbu.shahni13
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

# Explain conditional statements

1. Conditional statements in Python are used to control the flow of a program based
on certain conditions.

2. They allow you to execute different blocks of code depending on whether a


specified condition evaluates to True or False.

3. The primary conditional statements in Python are if, elif (short for "else if"),
and else.
# Types:
1. if Statement:
The if statement is used to execute a block of code only if a specified
condition is true.

2. if-else Statement:
The if-else statement extends the if statement by providing an alternative block
of code to n execute when the condition is fals

3. if-elif-else Statement:
The if-elif-else statement allows you to check multiple conditions in sequence.
If the first condition is false, it moves on to the next elif (else if)
condition, and so on. The else block is executed if none of the conditions
is true.

4. Nested Conditional Statements:


You can also nest conditional statements within each other to handle more
complex logic.

#wap to print which number is greater


a=10
b=20
if(a>b):
print("a is greater")
else:
print("b is greater")

#wap to print even or odd number


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

#wap to print number is positive or negative


number=int(input("enter any number"))
if(number>0):
print("number is positive ")
else:
print("number is negative")
#wap to print number is positive negative and zero
number=int(input("enter any number"))
if(number>0):
print("number is positive ")
elif(number<0):
print("number is negative")
else:
print("number is zero")

#wap to print grade according to your marks


# marks>90---->A grade
# marks>80---->B grade
# marks>70---->C grade
# marks>60---->D grade
# other fail

marks=int(input("enter your marks"))


if(marks>=90):
print("you are in A grade")
elif(marks>=80):
print("you are in B grade")
elif(marks>=70):
print("you are in C grade")
elif(marks>=60):
print("you are in D grade")
else:
print("sorry you are fail try again ")

#wap to print which value is greater


a=int(input('enter the value of a'))
b=int(input('enter the value of b'))
c=int(input('enter the value of c'))
if(a>b and a>c):
#print("A is greater")
print(f"A is greater{a}")
elif(b>a and b>c):
print("B is greater",b)
elif(c>a and c>b):
print("C is greater")
else:
print("you have enter same numbers")

#wap to check login and password


username=input("enter your user name")
password=input("enter your password ")
if username=="ajit" and password=="1234":
print("login successfully")
else:
print("invalid login")

#wap to swap two values wiithout using third varible

a=10
b=20
a,b=b,a
print(a)
print(b)

#wap to print calculator using conditional statements

number1=float(input("enter the value of number1"))


number2=float(input("enter the value of number3"))
op=input("enter the operation you want to perform +,-,*,/")
if(op=='+'):
result=number1+number2
print("addition of number1 and number2= ",result)
elif(op=='-'):
result=number1-number2
print("subtration of number1 and number2 = ",result)
elif(op=='*'):
result=number1*number2
print("multiplication of number1 and number2= ",result)
elif(op=='/'):
if(number2==0):
print("division is not possible by zero")
else:
result=number1/number2
print("division of number1 and number2 =",result)
else:
print("invalid operation")

# wap to calculate discount on your perchase by considering the following


conditions. If you perchase a amount of 5000 rupess you are not elegible for any
type of discount and if the total perchase amount is >5000 and less then 10000 then
there will be a discount of 10% and if you perchase amount>10000 and less then
15000 then you got a 15% discount and if you perchase a tottal of 20000 rupes you
are elegible for 20% discount
# total_perchase-----5000---no discount
# total_perchase----->5000 and less 10000---->10%
# total_perchase-----10000 and less 15000-----15%
# total_perchase-----20000 and so on ----20%
amount=int(input("enter your total amount of perchase"))
if(amount<=5000):
print("you are not elegible for any discount")
elif(amount>5000 and amount<10000):
print("you are elegible for 10% of discount")
discount=amount*0.10
print("the total discounted amount=",discount)
new_amount=amount-discount
print("THE NEW amount after discount of 10%",new_amount)
elif(amount>10000 and amount<15000):
print("you are elegible for 15% of discount")
discount=amount*0.15
print("the total discounted amount=",discount)
new_amount=amount-discount
print("THE NEW amount after discount of 15%",new_amount)
elif(amount>=15000 and amount<20000):
print("you are elegible for 20% of discount")
discount=amount*0.20
print("the total discounted amount=",discount)
new_amount=amount-discount
print("THE NEW amount after discount of 20%",new_amount)
else:
print("you are elegible for 22% of discount")
discount=amount*0.22
print("the total discounted amount=",discount)
new_amount=amount-discount
print("THE NEW amount after discount of 20%",new_amount)

# wap to calculate cost of a furniture which is sold on sunday with a heavy


discount on sunday of 15% but on other day there will be a charge of 10% calculate
the final cost

day=input("enter your day ")


perchase_amount=int(input("enter your total perchase amount"))
if(day=='sunday'):
print("you got a discount of 15%")
discount=perchase_amount*0.15
print("the discounted amount =",discount)
new_amount=perchase_amount-discount
print("the new discounted amount=",new_amount)
else:
print("you have to pay a charge of 10%")
charge=perchase_amount*0.10
print("the total 15% charge= ",charge)
new_amount=perchase_amount+charge
print("the total amount after 10% charge",new_amount)

# wap to calculate no of leave of an employ if the leaves <=5 in year then give a
bonus of 15% and if the leaves are more the 10 then deduct his salary by 20%
leaves=int(input("enter your total annual leaves "))
salary=int(input("enter your salary"))
if(leaves<=5):
print("you got a bonus of 15%")
bonus=salary*0.15
print("the total bonus amount",bonus)
new_salary=salary+bonus
print("salry after bonus",new_salary)
elif(leaves>=10):
print("you will be charge a tax of 10%")
deduct=salary*0.10
print("the total deducted amount",deduct)
new_salary=salary-deduct
print("salry after deduction",new_salary)
else:
print("you got nothing! please try again later")

You might also like