Problems (Lab2)

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Prepared by Sr. Lect. Dr.

Satish Paudel

Course No.: MEQ 114 Computer Aided Design


Lab 2 Operators, operands, and statements.
Q.1 Emmy wants to make a cup of chocolate milk by mixing melted sweetened chocolate and
fresh milk. When done, she wonders how much of all liquids added into the cup. Let’s write a
Python program that helps her calculate the liquid amount in milliliters (ml) and ounce (oz).
Suppose 1 ml = 0.0338 oz.
Output screen examples:
Enter amount of melted chocolate to be poured into the cup (ml): 350
Enter amount of milk to be poured into the cup (ml): 75
Now Emmy's cup is filled with 425.00 ml (or about 14.36 oz) of chocolate milk.
Enter amount of melted chocolate to be poured into the cup (ml): 110
Enter amount of milk to be poured into the cup (ml): 65
Now Emmy's cup is filled with 175.00 ml (or about 5.91 oz) of chocolate milk

Q.2 Write a Python program to calculate shaded area of the shape below. Note that the shape is
made up of a rectangle and a triangle so you can find the total shaded area by summing up the area
of those small parts.
Hint: Area of triangle =

Example of output screen:


Enter x: 4.5 Enter y: 5.0
Total area of the shape is 11.25 square units.
Prepared by Sr. Lect. Dr. Satish Paudel

Exercise 3. Write a program to calculate a cylinder in the following format. There program should
receive values of each parameter. The formula of a cylinder is r 2h. For this question, the Pi value
is equal to 3.1415926535. The output is format as follows "%.5f".

Question 4: Write a program that gets the full score and real score (not greater than full score)
from keyboard, and then show the percentage value of the full score.
Example screen:
----------------------------
--- Calculate Percentage ---
----------------------------
Full Score: 150 Real Score: 60
----------------------------
Percentage: 40.00%
----------------------------
All scores are float values.
The percent can print in the output using "%%".
Examples:
Prepared by Sr. Lect. Dr. Satish Paudel

Exercise 5: Write a program to receive a four-digit integer from the user. First, print out the result
of first two-digit sum last two-digit. Then print out the result of first two-digit minus last two-digit.
Last print out the result of integer value and remainder value of first two-digit divided by last two-
digit. All the numbers and the operations are using Integer.
(Hint: Find first two-digit and last two-digit) 2000 floor division 100 is equal to 20. 20 is then
become the first two digit. The 15 is the remainder from 2015 subtracts with 2000.
Input and Output:
Enter a four-digit integer: 2015
The result of 20 + 15 = 35
The result of 20 - 15 = 5
The integer value of 20/15 = 1
The remainder of 20/15 = 5
Prepared by Sr. Lect. Dr. Satish Paudel

Problem 6 Input three float numbers. Print out the average, summation and multiplication of
those numbers. The output is a format in 2 decimal points. The placeholder %.2f indicates two
decimal points format
Input and Output:

Enter the 1st number: 23

Enter the 2nd number: 4

Enter the 3rd number: 19

a,b,c = 23.00, 4.00, 19.00

The average of three integers = 15.33

The summation of three integers = 46.00

The multiplication of three integers = 1748.00

Exercise 7: Write a program that converts your weight and height from kilograms and centimeters
to pounds and feet, respectively. (1 kilogram = 2.20462262 pounds, 1 centimeter = 0.032808399
feet). The program output should look like this:
Enter your weight in kg.: 60
Enter your height in cm.: 170
Your weight in pounds = 132.27
Your height in feet = 5.58

Exercise 8: Write a program to takes two integer numbers as input data and display their sum,
difference, product (multiplication), and quotient. The program output should look like this:
Enter the first integer number: 8
Enter the second integer number: 22
The sum is 30
The difference is -14
The product is 176
The quotient is 0
Prepared by Sr. Lect. Dr. Satish Paudel

Problem 9. Input 6 numbers and print them out in reverse order.


Enter the first number: 1
Enter the second number: 2
Enter the third number: 3
Enter the first number: 4
Enter the second number: 5
Enter the third number: 6
Reverse order of 1 2 3 4 5 6 --> 6 5 4 3 2 1

Q.10 Calculate GPA from 3 subjects (ITS100, EL171, and SCS183) by multiply each subject with
its number of credits. After that, sum up all result and divide by total number of credits. Print out
the GPA result.
Note: ITS100 and EL171 have 3 credits. SCS183 has 1 credit.

You might also like