Professional Documents
Culture Documents
Question 15:- Write a program that prompts the user to input number of
calls and calculate the monthly telephone bills as per the following rule:
Minimum Rs. 200 for up to 100 calls. Plus Rs. 0.60 per call for next 50
calls. Plus Rs. 0.50 per call for next 50 calls. Plus Rs. 0.40 per call for any
call beyond 200 calls.
Code:-
#Question 15 call_number = int(input("Enter the number th of call")) if 0
<= call_number <= 100: print("Your bill is Rs.200") elif 101 <= call_number
<= 150: result = 200 + (call_number - 100)*(0.60) print(result) elif 151 <=
call_number <=200: result = 200 +30+(call_number-150)*(0.50)
print(result) else: result = call_number * (0.40) print(result)
Output:-
Question 16:- Write a program that prompts the user to input the value
of a (the coefficient of x2), b (the coefficient of x), and c (the constant
term) and outputs the roots of the quadratic equation.
Code:-
#Question 16 # Let quadratic equation is ax^2+bx+c a = int(input("Enter
The value of a")) b = int(input("Enter The value of b")) c = int(input("Enter
the value of c")) root1 = ((-b)+(b**2-4*a*c)**(1/2))/(2*a) root2 = ((-b)-
(b**2-4*a*c)**(1/2))/(2*a) print("The roots of quadratic eqution whose
coefficients are a,b,c is ",root1,'and',root2)
Output:-
Question 17:- Write a program that prompts the user to input a year and
determine whether the year is a leap year or not. Leap Years are any year
that can be evenly divided by 4. A year that is evenly divisible by 100 is a
leap year only if it is also evenly divisible by 400. Example: 1992 Leap Year
2000 Leap Year 1900 NOT a Leap Year 1995 NOT a Leap Year
Code:-
#Question 17 Year = int(input("Enter Year to check if leap or not")) if
Year%100==0 and Year%400==0: if Year%4==0: print("This is leap year")
else: pass else: print(Year,"is not leap year")
Output:-
Question 18:- The marks obtained by a student in 3 different subjects are
input by the user. Your program should calculate the average of subjects
and display the grade. The student gets a grade as per the following rules:
Average Grade 90-100 A 80-89 B 70-79 C 60-69. D 0-59 F
Code:-
#Question 18 subject1 = int(input("Enter the marks in 1st subject"))
subject2 = int(input("Enter the marks in 2nd subject")) subject3 =
int(input("Enter the marks in 3rd subject")) average =
(subject1+subject2+subject3)/3 if 90 <= average <= 100: print("Student
gets A grade") elif 80<= average <90 : print("Student gets B grade") elif
70<= average < 80 : print("Student gets C grade") elif 60<= average < 70:
print("Student gets D grade") else: print("Student gets F grade")
Output:-