What are the three main conditional statements in Python?
Answer: if, elif, and else
. What will be the output of the following Python code?
names_1 = ["Narendra", "Boyina", "raj", "Mahalakshmi"]
if 'Raj' in names_1:
print(1)
else:
print(2)
a) None
b) 1
c) 2
d) Error
Answer: c
Explanation: Python is case sensitive, "if" condition failed because "Raj" is not available in that list, "raj" is available, so else block statement is executed.
========================================================================
A company decided to give a bonus of 5% to the employee if his/her year of service is more than 5 years.
Ask users for their salary and year of service and print the net bonus amount.
Answer:
salary = int(input("Enter salary"))
yos = int(input("Enter year of service"))
if yos>5:
print "Bonus is",.05*salary
else:
print "No bonus"
========================================================================
========================================================================
========================================================================
Unit Price
First 100 units no charge
Next 100 units Rs 5 per unit
After 200 units Rs 10 per unit
(For example, if the input unit is 350 then the total bill amount is Rs2000)
logic.
amt=0
numer_units=int(input("Enter number of electric unit"))
if numer_units<=100:
amt=0
if numer_units>100 and numer_units<=200:
amt=(numer_units-100)*5
if numer_units>200:
amt=500+(numer_units-200)*10
print("Amount to pay :",amt)
========================================================================
Accept any city from the user and display a monument of that city.
City Monument
Delhi Red Fort
Agra Taj Mahal
Jaipur Jal Mahal
Answer
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")
========================================================================
========================================================================
Accept the following from the user and calculate the percentage of class attended:
a. Total number of working days
b. Total number of absent days
After calculating the percentage show that, If the percentage is less than 75 then the student will not be able to sit in the exam.
Answer
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")
========================================================================
Request: Please provide your valuable comments