40+ Important Python File Handling Practice Questions

Python File Handling Practice Questions Table of Content Python File Handling Practice Questions – Test 1 Python File Handling Practice Questions – Test 2 Python File Handling Practice Questions – Test 3 Python File Handling Practice Questions – Test 4 Python File Handling Practice Questions – Test 1 Q1. Name two types of data files … Read more

70+(solved) Important Practice Questions of Loops in Python

Practice Questions of loops in python
Practice Questions of loops in python

Practice Questions of Loops in Python — Test 1

Q1. Write the output of the following:

1.  for i in "Myblog":
         print (i, '?')

[showhide type="links1" more_text="Show Answer" less_text="Hide Answer"]Ans. 
M ?
y  ?
b ?
l  ?
o ?
g ?[/showhide]

2.  for i in range(5):
        print(i)

[showhide type="links2" more_text="Show Answer" less_text="Hide Answer"]Ans.
0
1
2
3
4[/showhide]

3. for i in range(10,15):
        print(i)

[showhide type="links3" more_text="Show Answer" less_text="Hide Answer"]Ans.
10
11
12
13
14[/showhide]

Q2. Write a program to print first 10 natural number.
[showhide type="links4" more_text="Show Answer" less_text="Hide Answer"]Ans.
for i in range(1,11):
      print(i)[/showhide]

Q3. Write a program to print first 10 even numbers.
[showhide type="links5" more_text="Show Answer" less_text="Hide Answer"]Ans.
for i in range(2,22,2):
     print(i)[/showhide]

Q4. Write a program to print first 10 odd numbers.
[showhide type="links6" more_text="Show Answer" less_text="Hide Answer"]Ans.
for i in range(1,21,2):
      print(i)[/showhide]

Q5. Write a program to print first 10 even numbers in reverse order.
[showhide type="links7" more_text="Show Answer" less_text="Hide Answer"]Ans.
for i in range(20,0,-2):
      print(i)[/showhide]

Q6. Write a program to print table of a number accepted from user.
[showhide type="links8" more_text="Show Answer" less_text="Hide Answer"]Ans.
num = int(input("Enter any number")
for i in range(1,11):
      print(num*i)[/showhide]

Q7. Write a program to display product of the digits of a number accepted from the user.
[showhide type="links9" more_text="Show Answer" less_text="Hide Answer"]Ans.

num=int(input("Enter any number"))
p=1
while(num):
   r=num%10
   p=p*r
   num=num//10
print("Product of digits is",p)[/showhide]

Q8. Write a program to find the factorial of a number.
[showhide type="links10" more_text="Show Answer" less_text="Hide Answer"]Ans.
num=int(input("Enter any number"))
f=1
for i in range(1,num+1):
    f=f*i
print("Factorial is",f)[/showhide]

Q9. Write a program to find the sum of the digits of a number accepted from user
[showhide type="links11" more_text="Show Answer" less_text="Hide Answer"]Ans.
num=int(input("Enter any number"))
s=0
while(num):
   r=num%10
   s=s+r
   num=num//10
print("Sum of digits is",s)[/showhide]

Q10. Write a program to check whether a number is prime or not.
[showhide type="links12" more_text="Show Answer" less_text="Hide Answer"]Ans.
num=int(input("Enter any number"))
f=0
if num==1 or num==0:
     f=1
for i in range(2,num):
     if num%i==0:
          f=1
if f==1:
     print("Number is not prime")
else:
     print("Number is prime")[/showhide]

Practice Questions of Loops in Python — Test 2

Q1. Write the output of the following

1. for i in (1,10):
       print(i)
[showhide type="links13" more_text="Show Answer" less_text="Hide Answer"]Ans
1
10[/showhide]

2. for i in (5,9):
       print(i)
[showhide type="links14" more_text="Show Answer" less_text="Hide Answer"]Ans.
5
9[/showhide]

3. for i in range(2,7):
       print(i)
[showhide type="links15" more_text="Show Answer" less_text="Hide Answer"]Ans.
2
3
4
5
6[/showhide]

4. for i in "csiplearninghub":
       print(i)
[showhide type="links16" more_text="Show Answer" less_text="Hide Answer"]Ans.
c
s
i
p
l
e
a
r
n
i
n
g
h
u
b[/showhide]

5. for i in "python":
       print(i, end=' ')
[showhide type="links17" more_text="Show Answer" less_text="Hide Answer"]Ans.
p y t h o n[/showhide]


6. for i in "python":
      print(i, end=='?')
[showhide type="links18" more_text="Show Answer" less_text="Hide Answer"]Ans.
p?y?t?h?o?n?[/showhide]

7. for i in "python":
        print(i, '?$')
[showhide type="links19" more_text="Show Answer" less_text="Hide Answer"]Ans.
p?$y?$t?$h?$o?$n?$[/showhide]

8. for i in (1,2,3,4):
       print(i)
[showhide type="links20" more_text="Show Answer" less_text="Hide Answer"]Ans.
1
2
3
4[/showhide]

9. for i in (3,4,7):
      print(i)
[showhide type="links21" more_text="Show Answer" less_text="Hide Answer"]Ans.
3
4
7
[/showhide]
10. for i in range(2,10,2):
     print(i)
[showhide type="links22" more_text="Show Answer" less_text="Hide Answer"]Ans
2
4
6
8[/showhide]

Practice Questions of Loops in Python — Test 6

Q1. Write the output of the following.

a=5
while a>0:
   print(a)
   a=a-1

[showhide type="links61" more_text="Show Answer" less_text="Hide Answer"]Ans.
5
4
3
2
1[/showhide]

Q2. for loop statement is terminated by symbol ___________

[showhide type="links62" more_text="Show Answer" less_text="Hide Answer"]Ans. Semicolon(;)[/showhide]

Q3. What is the difference between break and continue statements?

 

[showhide type="links63" more_text="Show Answer" less_text="Hide Answer"]Ans. break statement terminates the loop as the condition matches. for example.

a=5

while a>0:

a=a-1

if a==3: #as this condition matches it terminates the loop

break

else:

print(a)

Output : 4


Continue statement is used to skip a particular condition. for example

a=5

while a>0:

a=a-1

if a==3: #as this condition matches it goes to the next condition of the loop

continue

else:

print(a)

Output :
4
2
1
0
[/showhide]

Q4. Convert the following loop into for loop :
x = 4
while(x<=8):
    print(x*10)
    x+=2

[showhide type="links64" more_text="Show Answer" less_text="Hide Answer"]Ans.
for x in range(4,9,2):
print(x*10)[/showhide]

 

Q5. Write the output of the following:
for k in range(10,20,4):
    print(k)

[showhide type="links65" more_text="Show Answer" less_text="Hide Answer"]Ans.

10
14
18[/showhide]

Q6. Find errors in the following code:
x = input(“Enter value”)
for k in range[0,20]
    if x=k
        print(x+k)
   else:
       Print(x-k)

[showhide type="links66" more_text="Show Answer" less_text="Hide Answer"]Ans

x = input("Enter value")

for k in range(0,20):

  if x==k:

     print(x+k)

  else:

     print(x-k)[/showhide]

Q7. Write the output of the following:

x=3
if x>2 or x<5 and x==6:
    print(“Bye”)
else:
    print(“Thankyou”)

[showhide type=”links67″ more_text=”Show Answer” less_text=”Hide Answer”]Ans. Bye[/showhide]

Q8. Write the output of the following:

x,y=2,4
if(x+y==10):
    print(“Thankyou”)
else:
    print(“Bye”)

[showhide type=”links68″ more_text=”Show Answer” less_text=”Hide Answer”]Ans. Bye[/showhide]

Q9. Write the output of the following:

x=10
y=1
while x>y:
    x=x-4
    y=y+3
    print(x)

[showhide type="links69" more_text="Show Answer" less_text="Hide Answer"]Ans.

6
2[/showhide]

Q10. Write the output of the following:
for x in range(3):
    for y in range(2):
        print(“Practice Questions of loops in python”)
    print()

[showhide type="links70" more_text="Show Answer" less_text="Hide Answer"]Ans.

Practice Questions of loops in python
Practice Questions of loops in python

Practice Questions of loops in python
Practice Questions of loops in python

Practice Questions of loops in python
Practice Questions of loops in python[/showhide]


 

Practice Questions of Loops in Python — Test 7

Q1. What do you mean by jump statement?

Q2. What is nested loop?

Q3. Write a program to print the following pattern.

1    2     3    4 

1    2     3

1   2

1

Q4. Write a program to print the following pattern.

A

B    C

D    E    F

G    H    I    J

Q5. Write a program to print the following pattern.

A    A    A    A

A    A    A    A

A    A    A    A

A    A    A    A

Q6. Write a program to convert temperature in Fahrenheit to Celsius.

Q7. Write a program to print the factorial of a number.

Q8. Write a program to find the sum of digits of a number.

Q9. Accept two numbers from the user and display sum of even numbers between them(including both)

Q10. Write a program to reverse a number.

 

Class 12 Computer Science Sample Paper 2020-2021.

Class 12 Computer Science Sample Paper Marking Scheme

Class 12 Computer Science Test Series

70+ Python if else Statement Important Practice Questions

Table of Content

  1. Python if else Statement Practice – Test 1
  2. Python if else Statement Practice – Test 2
  3. Python if else Statement Practice – Test 3
  4. Python if else Statement Practice – Test 4
  5. Python if else Statement Practice – Test 5
  6. Python if else Statement Practice – Test 6
  7. Python if else Statement Practice – Test 7

Python if else Statement Practice Test 1

Q1. Name the keyword which helps in writing code involves condition.
[showhide type="links1" more_text="Show Answer" less_text="Hide Answer"]Ans. if [/showhide]

Q2. Write the syntax of simple if statement.
[showhide type="links2" more_text="Show Answer" less_text="Hide Answer"]
Ans. 
if < Condition> :
    Execute this[/showhide]

Q3. Is there any limit of statement that can appear under an if block.
[showhide type="links3" more_text="Show Answer" less_text="Hide Answer"]Ans. No[/showhide]

Q4. Write a program to check whether a person is eligible for voting or not. (accept age from user)
[showhide type="links4" more_text="Show Answer" less_text="Hide Answer"]Ans. 
age=int(input("Enter your age"))
if age >=18:
   print("Eligible for voting")
else:
   print("not eligible for voting")[/showhide]

Q5. Write a program to check whether a number entered by user is even or odd.
[showhide type="links5" more_text="Show Answer" less_text="Hide Answer"]Ans. 
num=int(input("Enter your age"))
if num%2==0:
   print("Number is Even")
else:
   print("Number is Odd")[/showhide]

Q6. Write a program to check whether a number is divisible by 7 or not.
[showhide type="links6" more_text="Show Answer" less_text="Hide Answer"]Ans.
num=int(input("Enter your age"))
if num%7==0:
   print("Number is divisible")
else:
   print("Number is not divisible")[/showhide]

Q7. Write a program to display "Hello" if a number entered by user is a multiple of five , 
otherwise print "Bye".
[showhide type="links7" more_text="Show Answer" less_text="Hide Answer"]Ans.
num=int(input("Enter your age"))
if num%5==0:
   print("Hello")
else:
   print("Bye")[/showhide]

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)
[showhide type="links8" more_text="Show Answer" less_text="Hide Answer"]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)[/showhide]
                                      
Q9. Write a program to display the last digit of a number.
(hint : any number % 10 will return the last digit)
[showhide type="links9" more_text="Show Answer" less_text="Hide Answer"]Ans.
num=int(input("Enter any number"))
print("Last digit of number is ",num%10)[/showhide]

Q10. Write a program to check whether the last digit of a number( entered by user ) is 
divisible by 3 or not.
[showhide type="links10" more_text="Show Answer" less_text="Hide Answer"]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 ")[/showhide]

Python if else

Python if else Statement Practice Test 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

[showhide type="links11" more_text="Show Answer" less_text="Hide Answer"]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")[/showhide]
    

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%

[showhide type="links12" more_text="Show Answer" less_text="Hide Answer"]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)[/showhide]

      
Q3. Write a program to check whether an years is leap year or not.

[showhide type="links13" more_text="Show Answer" less_text="Hide Answer"]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")[/showhide]

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.

[showhide type="links14" more_text="Show Answer" less_text="Hide Answer"]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")[/showhide]

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

[showhide type="links15" more_text="Show Answer" less_text="Hide Answer"]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")[/showhide]

Q6. What do you mean by statement?

[showhide type="links16" more_text="Show Answer" less_text="Hide Answer"]Ans. Executable lines in a program is called instruction

Q7. Write the output of the following:
     if True:     
        print(101)    
    else:    
       print(202)

[showhide type="links17" more_text="Show Answer" less_text="Hide Answer"]Ans. 101[/showhide]

Q8. Write the logical expression for the following:
A is greater than B and C is greater than D

[showhide type="links18" more_text="Show Answer" less_text="Hide Answer"]
Ans. A > B and C < D[/showhide]

Q9. Accept any city from the user and display monument of that city.
                  City                                 Monument
                  Delhi                               Red Fort
                  Agra                                Taj Mahal
                  Jaipur                              Jal Mahal

[showhide type="links19" more_text="Show Answer" less_text="Hide Answer"]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")[/showhide]
                        
Q10. Write the output of the following if a = 9
        
    if (a > 5 and a <=10):    
         print("Hello")    
    else:    
        print("Bye")

[showhide type="links20" more_text="Show Answer" less_text="Hide Answer"]Ans. Hello[/showhide]

Python if else

Python if else Statement Practice Test 3

Q1. Write a program to check whether a number entered is three digit number or not.

[showhide type="links21" more_text="Show Answer" less_text="Hide Answer"]Ans.

num1 = (input("Enter any number")
l=len(num1)
if l != 3:
     print("Enter three digit number")
else:
     print("Middle digit is ",(int(num1)%100//10))[/showhide]

Q2. Write a program to check whether a person is eligible for voting or not.(voting age >=18)

[showhide type="links22" more_text="Show Answer" less_text="Hide Answer"]Ans. 

age=int(input("Enter your age"))
if age >=18:
    print("Eligible for Voting")
else
    print("Not eligible for voting")[/showhide]

Q3. Write a program to check whether a person is senior citizen or not.

[showhide type="links23" more_text="Show Answer" less_text="Hide Answer"]Ans. 

age=int(input("Enter your age"))
if age >=60:
    print("Senior Citizen")
else
    print("Not a Senior Citizen")[/showhide]

Q4. Write a program to find the lowest number out of two numbers excepted from user.

[showhide type="links24" more_text="Show Answer" less_text="Hide Answer"]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)[/showhide]

Q5. Write a program to find the largest number out of two numbers excepted from user.

[showhide type="links25" more_text="Show Answer" less_text="Hide Answer"]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)[/showhide]

Q6. Write a program to check whether a number (accepted from user) is positive or negative.

[showhide type="links26" more_text="Show Answer" less_text="Hide Answer"]Ans. 
num1 = int(input("Enter first number"))
if num1 > 0 :
    print("Number is positive")
else:
    print("Number is negative")[/showhide]

Q7. Write a program to check whether a number is even or odd.

[showhide type="links27" more_text="Show Answer" less_text="Hide Answer"]Ans.

num1 = int(input("Enter first number"))
if num1%2==0:
    print("Number is even")
else:
    print("Number is odd")[/showhide]

Q8. Write a program to display the spell of a digit accepted from user (like user input 0 and display ZERO and so on)

Q8. Write a program to whether a number (accepted from user) is divisible by 2 and 3 both.

[showhide type="links28" more_text="Show Answer" less_text="Hide Answer"]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")[/showhide]

Q9. Write a program to find the largest number out of three numbers excepted from user.

[showhide type="links29" more_text="Show Answer" less_text="Hide Answer"]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)[/showhide]

Python if else

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.

[showhide type="links31" more_text="Show Answer" less_text="Hide Answer"]Ans. 

temp = int(input("Enter temperature of water"))
if temp >=100:
    print("Water is boiling")
else:
    print("Water is not boiling")[/showhide]

Q2. _________ is a graphical representation of steps (algorithm/flow chart)

[showhide type="links32" more_text="Show Answer" less_text="Hide Answer"]Ans. Flow chart[/showhide]

Q3. Python has _________ statement as empty statement (Pass/Fail)

[showhide type="links33" more_text="Show Answer" less_text="Hide Answer"]Ans. Pass[/showhide]

Q4. In python, a block is a group of _______statement having same indentation level.(consecutive/alternate)

[showhide type="links34" more_text="Show Answer" less_text="Hide Answer"]Ans. Consecutive[/showhide]

Q5. Out of “elif” and “else if”, which is the correct statement in python?

[showhide type="links35" more_text="Show Answer" less_text="Hide Answer"]Ans. elif[/showhide]

Q6. Accept the age of 4 people and display the youngest one?

[showhide type="links36" more_text="Show Answer" less_text="Hide Answer"]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)[/showhide]

Q7. What is the purpose of else in if elif ladder?

[showhide type="links37" more_text="Show Answer" less_text="Hide Answer"]Ans. If none of the condition is true in elif ladder then the else part will execute[/showhide]

Q8. Accept the age of 4 people and display the oldest one.

[showhide type="links38" more_text="Show Answer" less_text="Hide Answer"]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)[/showhide]

Q9. Write a program to check whether a number  is prime or not.

[showhide type="links39" more_text="Show Answer" less_text="Hide Answer"]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")[/showhide]

Q10. Write a program to check a character is vowel or not.

[showhide type="links40" more_text="Show Answer" less_text="Hide Answer"]Ans.

ch=input("Enter any character")
vow="aeiouAEIOU"
if ch in vow:
     print("Entered character is vowel")
else:
     print("Entered character is not vowel")[/showhide]

Python if else

Python if else Statement Practice Test 5

Q1. Accept the following from the user and calculate the percentage of class attended:

a.     Total number of working days

b.     Total number of days for absent

    After calculating percentage show that, If the percentage is less than 75, than student will not be able to sit in exam.

[showhide type="links41" more_text="Show Answer" less_text="Hide Answer"]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")[/showhide]

Q2. Accept the percentage from the user and display the  grade according to the following criteria:

  •     Below 25 —- D
  •     25 to 45 —- C
  •     45 to 50 —- B
  •     50 to 60 –– B+
  •     60 to 80 — A
  •     Above 80 –- A+
[showhide type="links42" more_text="Show Answer" less_text="Hide Answer"]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")[/showhide]

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.

[showhide type="links43" more_text="Show Answer" less_text="Hide Answer"]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)[/showhide]


Q4. Accept the marked price from the user and  calculate the Net amount as(Marked Price –    Discount) to pay according to following criteria:

Marked PriceDiscount
>1000020%
>7000 and <=1000015%
<=700010%
Python if else
[showhide type="links44" more_text="Show Answer" less_text="Hide Answer"]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)[/showhide]

Q5. Write a program to accept percentage and display the Category according to the  following criteria :

PercentageCategory
< 40Failed
>=40 & <55Fair
>=55 & <65Good
>=65Excellent
Python if else
[showhide type="links45" more_text="Show Answer" less_text="Hide Answer"]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")[/showhide]

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.

[showhide type="links46" more_text="Show Answer" less_text="Hide Answer"]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")[/showhide]

Q7. Write a program to accept two numbers and mathematical operators and perform operation accordingly.

Like:

Enter First Number: 7

Enter Second Number : 9

Enter operator : +

Your Answer is : 16

[showhide type="links47" more_text="Show Answer" less_text="Hide Answer"]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)[/showhide]

Q8. Accept the age, sex (‘M’, ‘F’), number of days and display the wages accordingly

AgeSexWage/day
>=18 and <30M700
F750
>=30 and <=40M800
F850
Python if else

If age does not fall in any range then display the following message: “Enter appropriate age”

[showhide type="links48" more_text="Show Answer" less_text="Hide Answer"]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")[/showhide]

Python if else

Python if else Statement Practice Test 6

Q1. Accept three numbers from the user and display the second largest number.

[showhide type="links51" more_text="Show Answer" less_text="Hide Answer"]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)[/showhide]

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)

[showhide type="links52" more_text="Show Answer" less_text="Hide Answer"]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")[/showhide]

Q3. Consider the following code

python conditional statement practice
Python if else

What will the above code print if the variables i, j, and k have the following values?

(a)    i = 3, j = 5, k = 7

(b)    i = -2, j = -5, k = 9

(c)    i = 8, j = 15, k = 12

(d)    i = 13, j = 15, k = 13

(e)    i = 3, j = 5, k = 17

(f)    i = 25, j = 15, k = 17

[showhide type="links53" more_text="Show Answer" less_text="Hide Answer"]Ans.

(a) 5  5  7

(b) 9 -5  9

(c) 8  12  12

(d) 13  13  13

(e) 5  5  17

(f) 17  15  17[/showhide]

Q4. Accept the electric units from user and calculate the bill according to the following rates.

First 100 Units     :  Free

Next 200 Units      :  Rs 2 per day.

Above 300 Units    :  Rs 5 per day.

if number of unit is 500 then total bill = 0 +400 + 1000 = 1400

[showhide type="links54" more_text="Show Answer" less_text="Hide Answer"]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)[/showhide]

Q5. Accept the number of days from the user and calculate the charge for library according to following :

Till five days : Rs 2/day.

Six to ten days  : Rs 3/day.

11 to 15 days  : Rs 4/day

After 15 days    : Rs 5/day

[showhide type="links55" more_text="Show Answer" less_text="Hide Answer"]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 * 5

print("Total amount to pay is ", amt)[/showhide]

Q6. Accept the kilometers covered and calculate the bill according to the following criteria:

First 10 Km              Rs11/km

Next 90Km               Rs 10/km

After that               Rs9/km

[showhide type="links56" more_text="Show Answer" less_text="Hide Answer"]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)[/showhide]

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

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))


[showhide type="links61" more_text="Show Answer" less_text="Hide Answer"]Ans.

1. True
2. True
3. False
4. False
5. False
6. False
7. True
8. True
9. True
10. True
11. True
12. True
13. True
14. True
15. True
16. True
17. True
18. True
19. False
20. True
21. False
22. False
23. False
24. False
25. True[/showhide]

Python if else

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.

Class 12 Computer Science Sample Paper 2020-2021.

Class 12 Computer Science Sample Paper Marking Scheme

Class 12 Computer Science Test Series

100 Important Python Fundamentals Practice Questions

Python Fundamentals Practice Questions Table of Contents Python Fundamentals Practice Questions – Test 1 Python Fundamentals Practice Questions – Test 2 Python Fundamentals Practice Questions – Test 3 Python Fundamentals Practice Questions – Test 4 Python Fundamentals Practice Questions – Test 5 Python Fundamentals Practice Questions – Test 6 Python Fundamentals Practice Questions – Test … Read more