Python Prob
Python Prob
Problem Statements
1. Input the base (b) and height (h) of a triangle and calculate its area where
Area of triangle =0.5* b * h
Solution
Department of CSE, PES University
UE24CS151A-Python for Computational Problem Solving
Laboratory Week 3
Explanation
Explanation:
The program prompts for base and height inputs.
It calculates the area using the formula
Area
=
1
2
×
base
×
height
Area=
2
1
×base×height.
Finally, it outputs the calculated area.
Department of CSE, PES University
UE24CS151A-Python for Computational Problem Solving
Laboratory Week 3
2. You are traveling to Kenya, if 1 Kenyan shilling = 0.65 Indian rupee. Calculate how many
shillings you will have based on the input in Indian Rupees.
Solution
Explanation
Understanding the Conversion
Exchange Rate
Department of CSE, PES University
UE24CS151A-Python for Computational Problem Solving
Laboratory Week 3
The given exchange rate is 1 KES = 0.65 INR. This means that for every Kenyan
shilling, you need 0.65 Indian rupees.
To find out how many shillings you can get for a certain amount of rupees, you need to
rearrange the formula.
Conversion Formula
To convert INR to KES, you use the formula:
KES
=
INR
0.65
KES=
0.65
INR
Department of CSE, PES University
UE24CS151A-Python for Computational Problem Solving
Laboratory Week 3
3. A grocery store offers a 10% discount on all purchases. Write a program that asks the
user for the total amount of their purchase, applies the discount and prints the total.
Solution
Explanation
4. You need to introduce yourself to your new classmates. What will you say as an ice
breaker? Display it in the format: My name is _____ and a fun fact about me is ____
Solution
Department of CSE, PES University
UE24CS151A-Python for Computational Problem Solving
Laboratory Week 3
Explanation
Start by defining a function that takes two inputs (name and fun fact) and formats them
into a string.
Use the input() function to get the user's name and fun fact.
Print the formatted introduction.
Department of CSE, PES University
UE24CS151A-Python for Computational Problem Solving
Laboratory Week 3
5. You go out for dinner with your friends and need to split the bill equally, how will you do
so by taking input of the bill amount and number of friends?
Solution
Department of CSE, PES University
UE24CS151A-Python for Computational Problem Solving
Laboratory Week 3
Explanation
6. You have a certain amount of total work(n) that needs to be shared among a fixed
number of workers m. Write a program to calculate the amount of work for each worker
and how much extra work is left. Take input for no. of work and no. of workers.
eg:
n = 100
m=6
Solution
Department of CSE, PES University
UE24CS151A-Python for Computational Problem Solving
Laboratory Week 3
Explanation
7. Tiling of a rectangular floor is performed. Write a program that calculates the number of
tiles required and the total cost to tile the entire floor. Take the dimensions of the floor
and the size and price of each tile as input from the user. Also consider labor charges.
Input:
Solution
Department of CSE, PES University
UE24CS151A-Python for Computational Problem Solving
Laboratory Week 3
Explanation
This program effectively calculates how many tiles are needed to cover a rectangular
floor and provides a detailed breakdown of costs involved in tiling, including both
materials and labor charges. It incorporates user input validation to ensure that all
entered values are numeric and valid for calculations.
Department of CSE, PES University
UE24CS151A-Python for Computational Problem Solving
Laboratory Week 3
8. Two persons A and B are conducting a Chemical experiment. In which A is user element
D and E in ratio of 2:1 and B uses the ratio of 4:3, calculate the mass of the compound if
each generates a 1 mole gram of substance given that the mass of D is 1 unit(amu) and
E is 5 units(amu). Take the values from the user.
Hint - Consider using split() method on the input string
eg-
"1:2".split(":") # [‘1’,’2’]
a,b = "1:2".split(":") # a <- '1' ; b <- ‘2
a,b = int(a), int(b) # type casting char/string to integers
Solution
Department of CSE, PES University
UE24CS151A-Python for Computational Problem Solving
Laboratory Week 3
Explanation
9. Given a 4 digit integer no. , display the individual digit & compute the sum of digits.
Solution
Department of CSE, PES University
UE24CS151A-Python for Computational Problem Solving
Laboratory Week 3
Explanation
10. You are asked to color quarter of a circle withreed, one third of the remaining with blue
and rest in yellow, find the area covered by each color and perimeter of each color
(include inner boundaries also ). Take radius as input.
Solution
Department of CSE, PES University
UE24CS151A-Python for Computational Problem Solving
Laboratory Week 3
Explanation
11. You've just celebrated your birthday, and you're curious about how many months, days,
and hours you've been alive. Write a Python program that takes your age(in years) as
input and prints your age in months and days.
Solution
Department of CSE, PES University
UE24CS151A-Python for Computational Problem Solving
Laboratory Week 3
Explanation
12. Imagine you've just opened a savings account at your local bank. You're curious how
much interest you'll earn after a few years. Write a Python program that calculates the
simple interest based on the amount you've deposited, the bank’s interest rate, and the
number of years you plan to keep the money in the account.
Solution
Department of CSE, PES University
UE24CS151A-Python for Computational Problem Solving
Laboratory Week 3
Explanation
13. You’re planning a vacation to a different country, but their weather forecasts are in
Celsius, and you’re more familiar with Fahrenheit. Write a Python program to help you
convert temperatures from Celsius to Fahrenheit so you can pack accordingly for your
trip! (use the formula: F = C * 9/5 + 32)
Solution
Department of CSE, PES University
UE24CS151A-Python for Computational Problem Solving
Laboratory Week 3
Explanation
14. You’re baking a cake, but the recipe you’re following is for 12 servings, and you need to
make enough for a different number of people. Write a Python program that takes the
number of servings you want to make and adjusts the ingredients accordingly. If the
recipe calls for 2 cups of sugar for 12 servings, calculate how many cups of sugar you'll
need for the number of servings entered by the user.
Solution
Department of CSE, PES University
UE24CS151A-Python for Computational Problem Solving
Laboratory Week 3
Explanation
15. You're throwing a pizza party for your friends, and you want to make sure everyone gets
an equal number of slices. Write a Python program that takes the number of pizzas,
slices per pizza, and the number of people attending the party as input, and calculates
how many slices each person gets. Also, calculate how many slices will be left over.
Solution
Department of CSE, PES University
UE24CS151A-Python for Computational Problem Solving
Laboratory Week 3
Explanation