Problem Set - 1_ Variables, Math Logical Operators (1)
Problem Set - 1_ Variables, Math Logical Operators (1)
1 Write a program to take in the name and age as inputs from the user. Print a message
in the terminal and make Python introduce yourself.
Example
2 Write a program to take a number as input from the user and check if the number is
odd or even. Print the label: "The number is odd/even".
Example:
3 Write a program to take in two variables x and y as inputs from the user. Assign the
values to each of them such that the value of x is greater than the value of y (x > y).
Find out their:
● Sum
● Difference
● Product
● Division
Finally, print each of them with a label: "Their <operation> is: <result>”.
Example *
Example:
5 Write a program to check if a shape is a triangle or not. The program will take three
numbers as inputs from the user, which are the angles of the triangle (the value
should be greater than 0 degrees and less than 180 degrees). Finally, print whether
the shape is a triangle or not with simply a "Yes" or a "No".
[HINT: A shape is a valid triangle if, and only if, the sum of all its angles is 180
degrees]
Example
*
Sample Input Sample Output
90 45 45 Yes
30 110 40 Yes
0 180 0 No
160 20 30 No
6 You are given three positive integers a, b, and c, where a and b are the sides of a
right-angled triangle, and c is the hypotenuse. Write a program that takes these three
integers as inputs from the user, and determines if the triangle is special or not.
*
If the triangle is special, print “Special Triangle”. Else print “Not special”.
Enter a: 4 Special
Enter b: 3
Enter c: 5
Start by:
● Asking the choice of the conversion, "Enter the choice of conversion:".
● Next, ask, "Enter the temperature in Celsius/Fahrenheit:".
8 You are developing an application for a supermarket checkout. Write a program that
would take the name of an item, its price, and how many of it is being purchased by
the customer (the quantity). You need to take the name, price, and quantity as inputs
from the user: **
● Begin by asking with the label, "Enter the item name:" to get the name of the
item.
● Next, ask, "Enter the price of the item:" to get the price of the item.
● Finally, ask, "Enter the quantity of the item:" to get the quantity of the item the
customer is purchasing.
Examples
Enter item name: Apple The total price of Apple purchased: 20 BDT
Enter item price: 10
Enter item quantity: 2
Enter item name: Speaker The total price of Speaker purchased: 10000 BDT
Enter item price: 1000
Enter item quantity: 10
9 Write a simple program that helps users calculate the area and
perimeter/circumference of different shapes based on their choice. The program
should ask the user to input a number corresponding to the shape they want to
calculate. The choices are as follows:
● If the user input value is 1, then calculate the area for a circle.
● If it is 2, then calculate the area for a square.
● If it is 3, then calculate the area for a rectangle.
● If it is 4, then calculate only the area for a triangle.
After choosing the shape, the program should ask for the necessary values:
● For a circle, ask for the radius.
● For a square, ask for the length of a side.
● For a rectangle, ask for the lengths of two sides.
● For a triangle, ask for the base and height. **
Calculate their area and finally, print the values in the terminal. See the inputs and
corresponding outputs in the examples below.
10 You are developing a grade-checking system for UIU. Write a program to take the final
score/marks as user input. Print the output of the final grade along with its remarks in
the format:
"Grade: <grade>, <remarks>".
**
Examples
50 Grade: F, Fail
11 You are developing a payroll system for a company. The system has a feature to give
a bonus to an employee if they fulfil all the conditions such as:
● The work hours must be greater than 20 hours/week.
● The employee must have been in the company for at least 2 years.
If an employee doesn’t meet these conditions, they are not eligible for a bonus.
If an employee has these conditions fulfilled, then may be awarded any bonus from
three types of categories: Gold, Silver, and Bronze. The conditions and rewards to
meet the categories are as follows:
● If their productivity is within the range of 0.5-0.69, then they will be awarded a
Bronze bonus.
● If their productivity is within the range of 0.70-0.89, then they will be awarded a
Silver bonus.
● If their productivity is within the range of 0.90-1.00, then they will be awarded a
Gold bonus.
● Else, give a normal bonus.
Write a program to take in the employee name, work hours, years of work, tasks done,
and tasks given as inputs from the user (print labels to take inputs, see examples for
more). Based on the conditionals, find if the employee is eligible for a bonus and print
the bonus category.
Example
Enter employee name: John Doe John Doe is not eligible for a bonus
Enter the work hours: 20
Enter years of work: 3
Enter tasks done: 12
Enter tasks given: 12
Enter employee name: Jane Doe Jane Doe is eligible for the Silver bonus
Enter the work hours: 23
Enter years of work: 4
Enter tasks done: 12
Enter tasks given: 14
Enter employee name: Mrs Y Mrs Y is eligible for the Gold bonus
Enter the work hours: 21
Enter years of work: 10
Enter tasks done: 18
Enter tasks given: 20
Enter employee name: Jack Doe Jack Doe is eligible for the Bronze bonus
Enter the work hours: 21
Enter years of work: 5
Enter tasks done: 13
Enter tasks given: 20
12 Robin Hood steals money from the rich and gives it to the poor, but conditionally.
Before deciding to steal, he sees the population of his town at a particular hour. If the
number of rich people in the town is more than the number of poor people, he does
not steal. If he sees that the number of poor people is more than the number of rich
people, he will only steal if both:
● The number of poor people is a multiple of 4.
● The number of rich people is a multiple of 3.
Write a program for Robin Hood where he will input the number of poor people and
the number of rich people. The program will tell whether or not Robin Hood should
steal at that time of the day. The program will output either “Do not steal” or “Steal”
Example *
Example
a Vowel
p Not a vowel
14 A T20 cricket game lasts 20 overs. The analysts need to predict if the team chasing
down the target can win the game or not, given their current runs and number of overs
finished. In order to make a fair (but not accurate) prediction, the analysts calculate
the run rate and assume that the team will maintain this run rate till the end of the
game. Next, they estimate the amount of runs the team will score within the remaining
overs by taking the product of the run rate and the number of overs remaining. If
the estimated score is greater than the target to be chased, then the team is predicted
to win. If not, then the team will lose.
Help the analysts write this program. Ask the analysts for the number of runs scored,
the number of overs finished, and the current target. Finally, print “Might win” if the
team is predicted to win, else “Might lose”.
Example
For sample input 1: The run rate is 150/15 = 10. There are 5 overs remaining, which
means the estimate runs the team will score is 50. The runs left to chase is 60. The
team cannot win if they maintain this run rate.
15 Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the
ripest one, in their opinion. After that the watermelon was weighed, and the scales
showed a certain number of kilos. They rushed home, dying of thirst, and decided to
divide it, however they faced a hard problem.
Pete and Billy are great fans of even numbers, that's why they want to divide the
watermelon in such a way that each of the two parts weighs even number of kilos,
at the same time it is not obligatory that the parts are equal. The boys are extremely
tired and want to start their eating as soon as possible, that's why you should help
them and find out, if they can divide the watermelon in the way they want. For sure,
each of them should get a part of positive weight.
Print YES, if the boys can divide the watermelon into two parts, each of them weighing
even number of kilos; and NO in the opposite case.
*
Example
8 YES
2 NO
Explanation
For sample input 1: the boys can divide the watermelon into two parts of 2 and 6
kilos respectively (another variant — two parts of 4 and 4 kilos).