Q4
P.I.P: - 3.2
Q8. Predict the output of following code:
num = 20.5
z = 3
result = 2 + z * z ** 3 + num // z
print (result)
(a) Firstly, determine the answer without running the code and write.
(b) Now type the above code in script mode and test-run the program. Write below the result given by Python.
Answer =
(i)
It is based on your thinking that how you execute the above program in your mind. So do you self.
(ii)
Output:-
89.0
>>>
Q9. Write a program to read a floating point number n. Print n, n2, n3, n4 and n5.
Answer =
num = float (input ("Enter the number :- "))
print ("Answer is :- ", num, ', ', num **2, ', ', num ** 3, ', ', num ** 4, ' &', num ** 5)
Q10. Write a program that calculates the volume and surface area of a sphere. The program must first ask the user to key in a radius value, r, before it performs the calculations. The program should display the result of the calculations. Save the program as "sphere.py".
Use the following formulae:
Surface area, S = 4 π r2
Volume, V = 4 / 3(π r3)
π = 3.142
Answer =
First make a module name with "sphere.py". Then write the program.
r = float (input ("Enter the Radius of sphere :- "))
print ("Surface Area :- ", 4 * 3.142 * r ** 2)
print ("Volume :- ", 4 / 3 * (3.142 * r ** 3))
P.I.P: - 3.3
Q4. Write a short program that asks for your height in centimeters and then converts your height to feet and inches. (1 foot -12 inches, 1 inch = 2.54 cm)
Answer =
height = float (input ("Enter the Height in cm :- "))
print ("Height in Feet :- ", (height / 2.54) / 12 )
print ("Height in inches :- ", height / 2.54)
Q5. Write a program to find the area of a triangle using formula 1 / 2 * base * height.
Answer =
height = float (input ("Enter the Height :- "))
base = float (input ("Enter the Base :- "))
print ("Area of triangle :- ", 1 / 2 * height * base)
Q6. Write a program to read two numbers and print their quotient and remainder.
Answer =
num1 = int (input ("Enter the first number :- "))
num2 = int (input ("Enter the second number :- "))
print ("Quotient :- ", num1 // num2 )
print ("Remainder :- ", num1 % num2)
Q7. Write a program to compute simple interest and compound interest.
Answer =
p = int(input("Enter principal amount = "))
r = int(input("Enter the rate = "))
t = int(input("Enter time = "))
si = (p * r * t ) / 100
com = p * ( (1 + (r / 100 ))** t ) - p
print("Simple interest = ",si)
print("Compund interest = ",com)
Comments
Post a Comment