Ans.
num=int(input("Enter your age"))
if num%5==0:
print("Hello")
else:
print("Bye")
Q8. Write a program to calculate the electricity bill (accept number of unit from user) according to the following criteria :
Unit Price
First 100 units no charge
Next 100 units Rs 5 per unit
After 200 units Rs 10 per unit
(For example if input unit is 350 than total bill amount is Rs2000)
Ans.
amt=0
nu=int(input("Enter number of electric unit"))
if nu<=100:
amt=0
if nu>100 and nu<=200:
amt=(nu-100)*5
if nu>200:
amt=500+(nu-200)*10
print("Amount to pay :",amt)
Q9. Write a program to display the last digit of a number.
(hint : any number % 10 will return the last digit)
Ans.
num=int(input("Enter any number"))
ld=num%10
if ld%3==0:
print("Last digit of number is divisible by 3 ")
else:
print("Last digit of number is not divisible by 3 ")
Python if else Statement PracticeTest 2
Q1. Write a program to accept percentage from the user and display the grade according to the following criteria:
Marks Grade
> 90 A
> 80 and <= 90 B
>= 60 and <= 80 C
below 60 D
Ans.
per = int(input("Enter marks"))
if per > 90:
print("Grade is A")
if per > 80 and per <=90:
print("Grade is B")
if per >=60 and per <= 80:
print("Grade is C")
if per < 60:
print("Grade is D")
Q2. Write a program to accept the cost price of a bike and display the road tax to be paid according to the following criteria :
Cost price (in Rs) Tax
> 100000 15 %
> 50000 and <= 100000 10%
<= 50000 5%
Ans.
tax = 0
pr=int(input("Enter the price of bike"))
if pr > 100000:
tax = 15/100*pr
elif pr >50000 and pr <=100000:
tax = 10/100*pr
else:
tax = 5/100*pr
print("Tax to be paid ",tax)
Q3. Write a program to check whether an years is leap year or not.
Ans.
yr=int(input("Enter the year"))
if yr%100==0:
if yr%400==0:
print("Entered year is leap year")
else:
print("Entered year is not a leap year")
else:
if yr%4==0:
print("Entered year is leap year")
else:
print("Entered year is not a leap year")
Q4. Write a program to accept a number from 1 to 7 and display the name of the day like 1 for Sunday , 2 for Monday and so on.
Ans.
num=int(input("Enter any number between 1 to 7 : "))
if num==1:
print("Sunday")
elif num==2:
print("Monday")
elif num==3:
print("Tuesday")
elif num==4:
print("Wednesday")
elif num==5:
print("Thursday")
elif num==6:
print("Friday")
elif num==2:
print("Saturday")
else:
print("Please enter number between 1 to 7")
Q5. Write a program to accept a number from 1 to 12 and display name of the month and days in that month like 1 for January and number of days 31 and so on
Ans.
num=int(input("Enter any number between 1 to 7 : "))
if num==1:
print("January")
elif num==2:
print("February")
elif num==3:
print("March")
elif num==4:
print("April")
elif num==5:
print("May")
elif num==6:
print("June")
elif num==7:
print("July")
elif num==8:
print("August")elif num==9:
print("September")elif num==10:
print("October")elif num==11:
print("November")elif num==12:
print("December")
else:
print("Please enter number between 1 to 12")
Ans.
city = input("Enter name of the city")
if city.lower()=="delhi":
print("Monument name is : Red Fort")
elif city.lower()=="agra":
print("Monument name is : Taj Mahal")
elif city.lower()=="jaipur":
print("Monument name is : Jal Mahal")
else:
print("Enter correct name of city")
Q10. Write the output of the following if a = 9
if (a > 5 and a <=10):
print("Hello")
else:
print("Bye")
Ans.
num1 = int(input("Enter first number"))
num2 = int(input("Enter second number"))
if num1 > num2:
print("smaller number is :", num2)
else:
print("smaller number is :", num1)
Q5. Write a program to find the largest number out of two numbers excepted from user.
Ans.
num1 = int(input("Enter first number"))
num2 = int(input("Enter second number"))
if num1 > num2:
print("greater number is :", num1)
else:
print("greater number is :", num2)
Q6. Write a program to check whether a number (accepted from user) is positive or negative.
Ans.
num1 = int(input("Enter first number"))
if num1%2==0 and num1%3==0:
print("Number is divisible by 2 and 3 both")
else:
print("Number is not divisible by both")
Q9. Write a program to find the largest number out of three numbers excepted from user.
Ans.
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("Greatest number is ", num1)
if num2 > num1 and num2 > num3:
print("Greatest number is ", num2)
if num3 > num2 and num3 > num1:
print("Greatest number is ", num3)
Python if else Statement Practice Test 4
Q1. Accept the temperature in degree Celsius of water and check whether it is boiling or not (boiling point of water in 100 oC.
Ans.
age1=int(input("Enter age of first person"))
age2=int(input("Enter age of second person"))
age3=int(input("Enter age of third person"))
age4=int(input("Enter age of fourth person"))
if age1 < age2 and age1 < age3 and age1 < age4:
print("Age of oldest person is ",age1)
if age2 <age1 and age2 < age3 and age2 < age4:
print("Age of oldest person is ",age2)
if age3 < age2 and age3 < age1 and age3 < age4:
print("Age of oldest person is ",age3)
if age4 < age1 and age4 < age2 and age4 < age3:
print("Age of oldest person is ",age4)
Q7. What is the purpose of else in if elif ladder?
Ans.
age1=int(input("Enter age of first person"))
age2=int(input("Enter age of second person"))
age3=int(input("Enter age of third person"))
age4=int(input("Enter age of fourth person"))
if age1 > age2 and age1 > age3 and age1 > age4:
print("Age of oldest person is ",age1)
if age2 > age1 and age2 > age3 and age2 > age4:
print("Age of oldest person is ",age2)
if age3 > age2 and age3 > age1 and age3 > age4:
print("Age of oldest person is ",age3)
if age4 > age1 and age4 > age2 and age4 > age3:
print("Age of oldest person is ",age4)
Q9. Write a program to check whether a number is prime or not.
Ans.
k=0
num1 = int(input("Enter any number"))
if num1 == 0 or num1 == 1:
k=1
for i in range(2,num1):
if num1%i == 0:
k = 1
if k==1:
print("number is not prime")
else:
print("number is prime")
Q10. Write a program to check a character is vowel or not.
Ans.
nd = int(input("Enter total number of working days"))
na = int(input("Enter number of days absent"))
per=(nd-na)/nd*100
print("Your attendance is ",per)
if per <75 :
print("You are not eligible for exams")
else:
print("You are eligible for writing exam")
Q2. Accept the percentage from the user and display the grade according to the following criteria:
Ans.
per = int(input("Enter percentage"))
if per> 80:
print("Grade is A+")
elif per >60 and per <=80:
print("Grade is A")
elif per > 50 and per <=60:
print("Grade is B+")
elif per > 45 and per <=50:
print("Grade is B")
elif per > 25 and per <=45:
print("Grade is C")
elif per <25:
print("Grade is D")
Q3. A company decided to give bonus to employee according to following criteria:
Time period of Service Bonus
More than 10 years 10%
>=6 and <=10 8%
Less than 6 years 5%
Ask user for their salary and years of service and print the net bonus amount.
Ans.
ser=int(input("Enter the time period of service"))
sal =int(input("Enter your salary"))
if ser > 10:
b=10/100*sal
if ser >=6 and ser <=10:
b = 8/100*sal
if ser < 6:
b = 5/100*sal
print("Bonus is ", b)
Q4. Accept the marked price from the user and calculate the Net amount as(Marked Price – Discount) to pay according to following criteria:
Ans.
na=0
d=0
mp=int(input("Enter marked price"))
if mp > 10000:
d = 20/100*mp
if mp > 7000 and mp <= 10000:
d = 15/100*mp
if mp <= 7000:
d = 10/100*mp
na = mp-d
print("Net amount to pay ", na)
Q5. Write a program to accept percentage and display the Category according to the following criteria :
Ans.
pr = int(input("Enter the percentage"))
if pr < 40:
print("Your Category is: Failed")
elif pr >= 40 and pr < 55:
print("Your Category is: Fair")
elif pr >=55 and pr < 65:
print("Your Category is: Good")
elif pr >= 65 and pr<=100:
print("Your Category is: Excellent")
elif pr >100:
print("Please enter correct percentage")
Q6. Accept three sides of a triangle and check whether it is an equilateral, isosceles or scalene triangle.
Note :
An equilateral triangle is a triangle in which all three sides are equal.
A scalene triangle is a triangle that has three unequal sides.
An isosceles triangle is a triangle with (at least) two equal sides.
Ans.
s1=int(input("Enter first side of triangle"))
s2=int(input("Enter second side of triangle"))
s3=int(input("Enter third side of triangle"))
if s1==s2 and s2 == s3:
print("Equilateral triangle")
if (s1==s2 and s2!=s3) or (s2==s3 and s2!=s1) or (s1==s3 and s1!=s2):
print("Isosceles Triangle")
if s1!=s2 and s1!=s3 and s2!=s3:
print("Scalene Triangle")
Q7. Write a program to accept two numbers and mathematical operators and perform operation accordingly.
Ans
num1=int(input("Enter first number"))
num2=int(input("Enter second number"))
op=input("Enter mathematical operator")
if op=='+':
print("Result is ", num1+num2)
if op=='-':
print("Result is ", num1-num2)
if op=='*': print("Result is ", num1*num2)
if op=='/':
print("Result is ", num1/num2)
if op=='%':
print("Result is ", num1%num2)
if op=='**':
print("Result is ", num1**num2)
if op=='//':
print("Result is ", num1//num2)
Q8. Accept the age, sex (‘M’, ‘F’), number of days and display the wages accordingly
Age
Sex
Wage/day
>=18 and <30
M
700
F
750
>=30 and <=40
M
800
F
850
Python if else
If age does not fall in any range then display the following message:“Enter appropriate age”
Ans.
age=int(input("Enter your age"))
sex=input("Enter sex(M/F) ")
nd = int(input("Enter number of days"))
if age >=18 and age < 30 and sex.upper( ) == 'M':
amt = nd*700
print("Total wages is : ", amt)
elif age >=18 and age < 30 and sex.upper( ) == 'F':
amt = nd*750
print("Total wages is : ", amt)
elif age >=30 and age <= 40 and sex.upper( ) == 'M':
amt = nd * 800
print("Total wages is : ", amt)
elif age >=30 and age <= 40 and sex.upper( ) == 'F':
amt = nd * 850
print("Total wages is : ", amt)
else:
print("Enter appropriate age")
Python if else Statement Practice Test 6
Q1. Accept three numbers from the user and display the second largest number.
Ans.
num1=int(input("Enter first number"))
num2=int(input("Enter second number"))
num3=int(input("Enter third number"))
if (num1 > num2 and num1 < num3) or (num1 < num2 and num1 > num3):
print("Middle number is " , num1)
if (num2 > num1 and num2 < num3) or (num2 < num1 and num2 > num3):
print("Middle number is" , num2)
if (num3 > num2 and num3 < num1) or (num3 < num2 and num3 > num1):
print("Middle number is" , num3)
Q2. Accept three sides of triangle and check whether the triangle is possible or not.
(triangle is possible only when sum of any two sides is greater than 3rd side)
Ans.
s1=int(input("Enter First side of triangle"))
s2=int(input("Enter Second side of triangle"))
s3=int(input("Enter Third side of triangle"))
if s1+s2 > s3 and s2 + s3 > s1 and s1 + s3 > s2:
print("Triangle is possible")
else:
print("Triangle not possible")
Q3. Consider the following code
What will the above code print if the variables i, j, and k have the following values?
Ans.
ut = int(input("Enter number of units"))
if ut <=100:
amt = 0
elif ut >100 and ut <= 300:
amt = (ut-100) *2
else:
amt = 400 + (ut - 300)*5
print("Total amount to pay is ", amt)
Q5. Accept the number of days from the user and calculate the charge for library according to following :
Ans.
nd = int(input("Enter number of days "))
if nd <= 5:
amt = nd * 2
elif nd >=6 and nd <=10:
amt = nd * 3
elif nd >= 11 and nd <= 15:
amt = nd * 4
else:
amt = nd * 5print("Total amount to pay is ", amt)
Q6. Accept the kilometers covered and calculate the bill according to the following criteria:
Ans.
kmc = int(input("Enter the kilometer covered"))
if kmc <=10 :
amt = kmc * 11
elif kmc > 10 and kmc <= 100:
amt = 110 + (kmc - 10)*10
elif kmc > 100:
amt = 1010 + (kmc - 100)*9
print("Total amount to pay is ", amt)
Q7. Accept the marks of English, Math and Science, Social Studies Subject and display the stream allotted according to following
All Subjects more than 80 marks — Science Stream
English >80 and Math, Science above 50 –Commerce Stream
English > 80 and Social studies > 80 — Humanities
Python if else Statement Practice Test 7
Q1. Evaluate the following statements:
a=True
b=True
c=True
d=True
1. print(c)
2. print(d)
3. print(not a)
4. print(not b )
5. print(not c )6. print(not d)
7. print(a and b )
8. print(a or b )
9. print(a and c)
10. print(a or c )
11. print(a and d )
12. print(a or d)
13. print(b and c )
14. print(b or c )
15. print(a and b or c)
16. print(a or b and c )
17. print(a and b and c)
18. print(a or b or c )
19. print(not a and b and c)
20. print(not a or b or c )
21. print(not (a and b and c))
22. print(not (a or b or c) )
23. print(not a and not b and not c)
24. print(not a or not b or not c )
25. print(not (not a or not b or not c))
The idea of giving above assignment of python if else is to give students a lot of practice of python if else concept and he/she would be able to do all types of question related to “python if else”
Disclaimer : I tried to give correct code of all the answers of above python if else assignments. The code is not copied from any other site or any other assignment of python if else. Please share feedback of above python if else assignment to csiplearninghub@gmail.com so that i can improve and give better content to you.
32 thoughts on “70+ Python if else Statement Important Practice Questions”
This is really use full. Please can you provide the answer for this one.
# Accept the marks of English, Math and Science, Social Studies Subject and display the stream allotted according to following
# All Subjects more than 80 marks — Science Stream
# English >80 and Math, Science above 50 –Commerce Stream
# English > 80 and Social studies > 80 — Humanities
if eng > 80 and mth > 80 and sci > 80 and sst > 80:
print(“Science Stream”)
elif eng > 80 and (80 > mth and sci > 50):
print(“Commerce Stream”)
elif (eng and sst > 80) and (mth and sci < 80):
print("Humanities")
m,e,s,so=map(int,input().split())
if m>80 and e>80:
if s>80 and so>80:
print(“alloted science stream”)
if e>80:
if m>50 and s>50:
print(“alloted commers”)
elif so>80:
print(“alloted humanites”)
eng = int(input(“Enter your English marks : “))
math = int(input(“Enter your Math marks : “))
science = int(input(“Enter your Science marks : “))
ss = int(input(“Enter your Social Studies : “))
if eng >= 80 and math >= 80 and science >= 80 and ss >= 80:
print (“Science Stream”)
elif eng >= 80 and (50>=math and science >= 50):
print (“Commerce Stream”)
elif eng >= 80 and (ss >=80):
print (“Humanities”)
a=int(input(“Please enter your English marks: “))
b=int(input(“Please enter your Maths marks: “))
c=int(input(“Please enter your Social Science marks: “))
d=int(input(“Please enter your Science marks: “))
if a>80 and b>80 and c>80 and d>80:
print(“The stream alloted to you is Science.”)
elif(a>80 and b>50 and d>50):
print(“The stream alloted to you is Commerce.”)
elif(a>80 and c>80):
print(“The stream alloted to you is Humanities.”)
else:
print(“Sorry! But no stream is alloted to you.”)
Write a program to calculate the electricity bill (accept number of unit from user) according to the following criteria :
Unit Price
First 100 units no charge
Next 100 units Rs 5 per unit
After 200 units Rs 10 per unit
(For example if input unit is 350 than total bill amount is Rs2000)
Firstly, the given code is written in 11 lines.
a) i=3, j=5, k=7 (consider these values for i, j and k)
As first line is true as it satisfies the condition for (i<j) i.e., 3<5, it ignores else block
which is at line 6 and enters into the "if" block which is at line 1. After entering inside the first "if" block which is at line 1. As again the condition is true at line 2, it enters into 3rd line thereafter "i" gets the value of "j" which means "i" value is 5 now. And ignores the
"else" block which is at line 4. So, it it directly goes to line 11 and prints the values for i,j and k…here i value becomes 5. 'J' and 'K' values don't change as they are not being
affected like i.
unit= int(input(“enter unit”))
if unit<=100:
print("their is no charges")
elif unit in range(101,201):
price=100*0+(unit-100)*5
print("your electricity bill is",price)
else:
price=100*0+500+(unit-200)*10
print(price)
amount=0
n=int(input(“Enter the units”)
if n>=100:
amount=0
if n>100 and n200
amount= 500 +(n-200)*10 // 100 units is rs 5 per unit (100*5=500)
print(“amount to be paid:”,amount)
bro in the question it said that for first 100 units its for free ,
then next 100 units you have to pay 5 ruppes per unit that means 100*5=500 ruppes and after 200 unit u have to pay 10 ruppes per unit that means previous 100*5=500 and after 200 units the formula is (num-200)*10 ruppes and also u have to pay the prevoius unit i.e. 500 thats why it written amt = 500+(num-200)*10
ME= int(input(‘Enter English Marks out of 100: ‘))
MM= int(input(‘Enter Maths Marks out of 100: ‘))
MS= int(input(‘Enter Science Marks out of 100: ‘))
MSS= int(input(‘Enter SST Marks out of 100: ‘))
SF = float(ME+MM+MS+MSS)
CF = float(ME+MM+MS+MSS)
Hm = float(MS+MSS)
if SF>=320:
print (‘You are eligible for Science Faculty’)
elif CF>=260 and CF=50 and Hm <200:
print ('You are eligible for Humanities')
(Its a junior and just a beginner Python programmer from Pakistan. I just tried this whole code on my own. Sb may find it a bit pathetic. Mee too. But it somehow ran. But not with accurate demanded Output. But to some extent. Need your guidance dear all. Thanks
science=int(input(“Enter Your Science Marks:”))
english=int(input(“Enter Your english marks:”))
math=int(input(“Enter your maths marks:”))
socialstu=int(input(“Enter Your marks Socialstudies:”))
allsubject = (science+english+math+socialstu)/400*100
if allsubject>80:
print(“You go for Science Stream”)
elif english>=80 and math>50 and science>50:
print(“You go for commerce stream”)
elif english>=80 and socialstu>80:
print(“You go for Humanities”)
else:
print(“You entered wrong subject”)
e= int(input(“Enter marks of English: “))
m= int(input(“Enter marks of Maths: “))
s= int(input(“Enter marks of Science: “))
ss= int(input(“Enter marks of Social Science: “))
if e>80 and m>80 and s>80 and ss>80:
print(“Science Stream allotted”)
elif e>80 and m>50 and s>50:
print(“Commerce Stream allotted”)
elif e>80 and ss>80:
print(“Humanities Stream allotted”)
english_marks = int(input(“Enter marks in English: “))
math_marks = int(input(“Enter marks in Mathematics: “))
science_marks = int(input(“Enter marks in Science: “))
computers_marks = int(input(“Enter marks in Computers: “))
a=int(input(“enter the umit:”))
if a<=100:
print("no charge")
elif 100<a<=200:
print("bonus is",5*a)
elif 200<a<350:
print("bonus is",10*a)
else:
print("bonus: if unit is 350 is",2000)
eng_marks=int(input(“Enter the marks in eng subject: “))
math_marks=int(input(“Enter the marks in math subject: “))
science_marks=int(input(“Enter the marks in science subject: “))
social_marks=int(input(“Enter the marks in social subject: “))
total_marks=eng_marks+math_marks+science_marks+social_marks
if eng_marks>80 and math_marks > 80 and science_marks > 80 and social_marks > 80:
print(“You are eligible for Science Stream”)
elif (eng_marks >80 and math_marks>80 )and science_marks >50 :
print(“You are eligible for the Commerce Stream”)
elif eng_marks > 80 and social_marks > 80:
print(“You are eligible for the Humanities”)
This is really use full. Please can you provide the answer for this one.
# Accept the marks of English, Math and Science, Social Studies Subject and display the stream allotted according to following
# All Subjects more than 80 marks — Science Stream
# English >80 and Math, Science above 50 –Commerce Stream
# English > 80 and Social studies > 80 — Humanities
Thankyou Ram babu.
eng = int(input(“ENGLISH : “))
sst = int(input(“SOCIAL STUDIES : “))
mth = int(input(“MATHS : “))
sci = int(input(“SCIENCE : “))
if eng > 80 and mth > 80 and sci > 80 and sst > 80:
print(“Science Stream”)
elif eng > 80 and (80 > mth and sci > 50):
print(“Commerce Stream”)
elif (eng and sst > 80) and (mth and sci < 80):
print("Humanities")
if mar > 80:
print(english,social,)
print(science stream,humanities)
elif mar >50 and mar <80:
print(math , science)
print("commerce stream")
m,e,s,so=map(int,input().split())
if m>80 and e>80:
if s>80 and so>80:
print(“alloted science stream”)
if e>80:
if m>50 and s>50:
print(“alloted commers”)
elif so>80:
print(“alloted humanites”)
Sir it is so easy question
eng = int(input(“Enter your English marks : “))
math = int(input(“Enter your Math marks : “))
science = int(input(“Enter your Science marks : “))
ss = int(input(“Enter your Social Studies : “))
if eng >= 80 and math >= 80 and science >= 80 and ss >= 80:
print (“Science Stream”)
elif eng >= 80 and (50>=math and science >= 50):
print (“Commerce Stream”)
elif eng >= 80 and (ss >=80):
print (“Humanities”)
a=int(input(“Please enter your English marks: “))
b=int(input(“Please enter your Maths marks: “))
c=int(input(“Please enter your Social Science marks: “))
d=int(input(“Please enter your Science marks: “))
if a>80 and b>80 and c>80 and d>80:
print(“The stream alloted to you is Science.”)
elif(a>80 and b>50 and d>50):
print(“The stream alloted to you is Commerce.”)
elif(a>80 and c>80):
print(“The stream alloted to you is Humanities.”)
else:
print(“Sorry! But no stream is alloted to you.”)
Hello, can you please tell me why the we need to have 500 for calculations nu>200 in Q8 Test1 ?
Q8. Write a program to calculate the electricity bill […]
if nu>200:
amt=500+(nu-200)*10
print(“Amount to pay :”,amt)
I don’t get it!
Hi
Actually first 100 units are free and next 100 units are charged @ 5/unit so for next 100 unit amount is 5*100=500
of course!!! thank you so much
Write a program to calculate the electricity bill (accept number of unit from user) according to the following criteria :
Unit Price
First 100 units no charge
Next 100 units Rs 5 per unit
After 200 units Rs 10 per unit
(For example if input unit is 350 than total bill amount is Rs2000)
if any one help on this.
I have a problem is Test 6, Ques no 3.???
Can anyone solve this by explaining in detail??
Firstly, the given code is written in 11 lines.
a) i=3, j=5, k=7 (consider these values for i, j and k)
As first line is true as it satisfies the condition for (i<j) i.e., 3<5, it ignores else block
which is at line 6 and enters into the "if" block which is at line 1. After entering inside the first "if" block which is at line 1. As again the condition is true at line 2, it enters into 3rd line thereafter "i" gets the value of "j" which means "i" value is 5 now. And ignores the
"else" block which is at line 4. So, it it directly goes to line 11 and prints the values for i,j and k…here i value becomes 5. 'J' and 'K' values don't change as they are not being
affected like i.
unit= int(input(“enter unit”))
if unit<=100:
print("their is no charges")
elif unit in range(101,201):
price=100*0+(unit-100)*5
print("your electricity bill is",price)
else:
price=100*0+500+(unit-200)*10
print(price)
amount=0
n=int(input(“Enter the units”)
if n>=100:
amount=0
if n>100 and n200
amount= 500 +(n-200)*10 // 100 units is rs 5 per unit (100*5=500)
print(“amount to be paid:”,amount)
x=int(input(“Enter the number of units: “))
amt=0
if x100 and x200:
amt=500+(x-200)*5
print(amt)
km = int(input(‘Enter kms = ‘))
if (km 10 and km <= 100):
charge = 110 + ((km- 10) * 10)
else:
charge = 1010 + (km – 100) * 9
print('total bill amount is ',charge)
units = float(input(“Enter electricity unit charges: “))
if units <= 50:
bill = units * 0.50
elif units <= 150:
bill = 50 * 0.50 + (units – 50) * 0.75
elif units <=250:
bill = 50 * 0.50 + 100 * 0.75 + (units – 100) * 1.20
else:
bill = 50 * 0.50 + 100 * 0.75 + 100 * 1.20 + (units – 100) * 1.50
surcharge = bill * 0.20
total_bill = bill + surcharge
print("Electricity bill: ", bill)
print("Surcharge: ", surcharge)
print("Total bill: ", total_bill)
For example
Enter unit is 450
100 = free
450-100= 350
350 __ 100 Ra 5 =500
250 ___ 250*10=2500
2500+500= 3000
bro in the question it said that for first 100 units its for free ,
then next 100 units you have to pay 5 ruppes per unit that means 100*5=500 ruppes and after 200 unit u have to pay 10 ruppes per unit that means previous 100*5=500 and after 200 units the formula is (num-200)*10 ruppes and also u have to pay the prevoius unit i.e. 500 thats why it written amt = 500+(num-200)*10
That’s amazing and please tell me that it’s enough for learn and practice the code in condition programs?
yes
ME= int(input(‘Enter English Marks out of 100: ‘))
MM= int(input(‘Enter Maths Marks out of 100: ‘))
MS= int(input(‘Enter Science Marks out of 100: ‘))
MSS= int(input(‘Enter SST Marks out of 100: ‘))
SF = float(ME+MM+MS+MSS)
CF = float(ME+MM+MS+MSS)
Hm = float(MS+MSS)
if SF>=320:
print (‘You are eligible for Science Faculty’)
elif CF>=260 and CF=50 and Hm <200:
print ('You are eligible for Humanities')
(Its a junior and just a beginner Python programmer from Pakistan. I just tried this whole code on my own. Sb may find it a bit pathetic. Mee too. But it somehow ran. But not with accurate demanded Output. But to some extent. Need your guidance dear all. Thanks
science=int(input(“Enter Your Science Marks:”))
english=int(input(“Enter Your english marks:”))
math=int(input(“Enter your maths marks:”))
socialstu=int(input(“Enter Your marks Socialstudies:”))
allsubject = (science+english+math+socialstu)/400*100
if allsubject>80:
print(“You go for Science Stream”)
elif english>=80 and math>50 and science>50:
print(“You go for commerce stream”)
elif english>=80 and socialstu>80:
print(“You go for Humanities”)
else:
print(“You entered wrong subject”)
# last digit print
num=int(input(‘enter the any number—>’))
b=num%10
print(b)
if b:
print(b)
else:
print(“0”)
Wowwwwwwww!!!! really helped me alot… studied it before my practical.
e= int(input(“Enter marks of English: “))
m= int(input(“Enter marks of Maths: “))
s= int(input(“Enter marks of Science: “))
ss= int(input(“Enter marks of Social Science: “))
if e>80 and m>80 and s>80 and ss>80:
print(“Science Stream allotted”)
elif e>80 and m>50 and s>50:
print(“Commerce Stream allotted”)
elif e>80 and ss>80:
print(“Humanities Stream allotted”)
english_marks = int(input(“Enter marks in English: “))
math_marks = int(input(“Enter marks in Mathematics: “))
science_marks = int(input(“Enter marks in Science: “))
computers_marks = int(input(“Enter marks in Computers: “))
average_percentage = (english_marks + math_marks + science_marks + computers_marks) / 4
if average_percentage > 80:
print(‘You got Science Stream’)
elif 60 <= average_percentage <= 80:
print('You got Commerce Stream')
elif 50 <= average_percentage < 60:
print('You got Arts Stream')
else:
print('Sorry! No stream is allotted to you')
a=int(input(“enter the umit:”))
if a<=100:
print("no charge")
elif 100<a<=200:
print("bonus is",5*a)
elif 200<a<350:
print("bonus is",10*a)
else:
print("bonus: if unit is 350 is",2000)
How do I get to while-loop?
eng_marks=int(input(“Enter the marks in eng subject: “))
math_marks=int(input(“Enter the marks in math subject: “))
science_marks=int(input(“Enter the marks in science subject: “))
social_marks=int(input(“Enter the marks in social subject: “))
total_marks=eng_marks+math_marks+science_marks+social_marks
if eng_marks>80 and math_marks > 80 and science_marks > 80 and social_marks > 80:
print(“You are eligible for Science Stream”)
elif (eng_marks >80 and math_marks>80 )and science_marks >50 :
print(“You are eligible for the Commerce Stream”)
elif eng_marks > 80 and social_marks > 80:
print(“You are eligible for the Humanities”)