0% found this document useful (0 votes)
2 views9 pages

Problem Set - 1_ Variables, Math Logical Operators (1)

The document contains a series of programming tasks designed to help learners practice basic programming concepts in Python. Each task requires user input and involves operations such as arithmetic calculations, condition checking, and data handling. The tasks range in complexity and cover various topics, including input validation, mathematical operations, and logical conditions.

Uploaded by

dumpotatcries
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views9 pages

Problem Set - 1_ Variables, Math Logical Operators (1)

The document contains a series of programming tasks designed to help learners practice basic programming concepts in Python. Each task requires user input and involves operations such as arithmetic calculations, condition checking, and data handling. The tasks range in complexity and cover various topics, including input validation, mathematical operations, and logical conditions.

Uploaded by

dumpotatcries
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

SL Questions Difficulty

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

Sample Input Sample Output


*
John Doe Hello! My name is John Doe and I am 53
53 years old.

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:

Sample Input Sample Output *


2 The number is even

15 The number is odd

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 *

Sample Input Sample Output

5 Their sum is: 9


4 Their difference is: 1
Their product is: 20
Their division is: 1.25
4 Write a program that will take three numbers as input from a user, but it will print only
the first and last numbers and skip the middle number.

Example:

Sample Input Sample Output *


20 50 100 First value = 20, Last value = 100

20 75 22 First value = 20, Last value = 22

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.

For a triangle to be special, it needs to satisfy the Pythagorean theorem

*
If the triangle is special, print “Special Triangle”. Else print “Not special”.

Continued on the next page


Examples

Sample Input Sample Output

Enter a: 4 Special
Enter b: 3
Enter c: 5

Enter a: 5 Not special


Enter b: 3
Enter c: 4

7 You are developing a menu-based application to convert temperature from Celsius to


Fahrenheit and vice versa. Write a program to take the choice of conversion, and the
temperature value inputs from the user. The choice of conversion are as follows:
● If the user input value is 1, then you need to convert the temperature from
Celsius to Fahrenheit.
● If the input value is 2, then you need to convert the temperature from
Fahrenheit to Celsius.

Start by:
● Asking the choice of the conversion, "Enter the choice of conversion:".
● Next, ask, "Enter the temperature in Celsius/Fahrenheit:".

Finally, print the converted temperature with the label:


"The converted temperature is <result> C/F". See the examples below. **
Examples

Sample Input Sample Output

Enter the choice of conversion: 1 The converted temperature is: 77 F


Enter the temperature in Celsius: 25

Enter the choice of conversion: 2 The converted temperature is: 25 C


Enter the temperature in Fahrenheit: 77

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.

Finally, print it with the label:


“The total price of <name> purchased: <total_price> BDT”.
See the examples below.

Examples

Sample Input Sample Output

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.

[NOTE: Take the value of pi 𝝅 as 3.14]

Continued on the next page


Examples

Sample Input Sample Output

Enter choice of shape: 1 Area of the circle: 78.5


Enter the radius: 5

Enter choice of shape: 2 Area of the square: 100


Enter the length: 10

Enter choice of shape: 3 Area of the rectangle: 50


Enter the length for one side: 10
Enter the length for another side: 5

Enter choice of shape: 4 Area of the triangle: 25


Enter the base: 5
Enter the height: 10

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>".

The grade table is as follows:

**
Examples

Sample Input Sample Output

91.5 Grade: A, Outstanding

50 Grade: F, Fail

75 Grade: B-, Above Average

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.

The productivity is defined as the number of tasks completed by the employee


divided by the number of tasks they were assigned. ***

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

Sample Input Sample Output

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: Mr X Mr X is eligible for the normal bonus


Enter the work hours: 21
Enter years of work: 10
Enter tasks done: 5
Enter tasks given: 12

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 *

Sample Input Sample Output

Number of rich people: 4 Do not steal.


Number of poor people: 2

Number of rich people: 4 Do not steal


Number of poor people: 5

Number of rich people: 4 Do not steal


Number of poor people: 8
Number of rich people: 6 Steal
Number of poor people: 8

13 The english alphabet contains 5 vowels. Write a program to take in an input


capital/small letter from the user and print whether the alphabet is a vowel or not.

Example

Sample Input Sample Output


*
A Vowel

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

Sample Input Sample Output


*

Runs: 150 Might lose


Overs bowled: 15
Target: 210

Runs: 200 Might lose


Overs bowled: 13
Target: 310

Runs: 210 Might win


Overs bowled: 13
Target: 310
Explanation

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

Sample Input Sample Output

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).

You might also like