0% found this document useful (0 votes)
43 views

CPS Lab 3.1

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views

CPS Lab 3.1

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Computational Problem Solving

Lab Sheet 3.1

If conditionals
1. Write a program to read a 3-digit integer x as input and print the digits from left to
right order (that is MSB to LSB), on separate lines. For example, if the input is 123, the
output is [ Hint : use % and // operations.]
1
2
3

2. Write a program to read an integer x as input and print the digits from right to left order
(that is LSB to MSB), on separate lines. For example, if the input is 123, the output is
3
2
1

3. Write a program that takes a 3-digit number as input and prints its reverse. For example,
if the input is 345 then the output is 543. Given that none of the digits is a 0.

4. You are tasked with writing a Python program that calculates income tax for individuals
based on their income and tax brackets. Your program should follow these rules:

The tax calculation is based on the following tax brackets:

• Up to $10,000: 5% tax

• $10,001 to $50,000: 10% tax

• $50,001 to $100,000: 20% tax

• Over $100,000: 30% tax

There is also an additional tax deduction of $500 for individuals over 65 years old. If an
individual has children, they receive a tax credit of $200 for each child. Write a Python
program that takes input for an individual's income, age, and the number of children
and calculates their income tax.

Problem Solving

5. Janmansh has to submit 3 assignments for Chingari before 10 pm and he starts to do the
assignments at X pm. Each assignment takes him 1 hour to complete. Can you tell
whether he'll be able to complete all assignments on time or not?

Input Format

The first line will contain T - the number of test cases. Then the test cases follow. The first
and only line of each test case contains one integer .X - the time when Janmansh starts
1
doing the assignments.

Output Format

For each test case, output Yes if he can complete the assignments on time. Otherwise,
output No.

You may print each character of Yes and No in uppercase or lowercase (for example, yes,
yEs, YES will be considered identical).

Constraints

1 ≤ T ≤ 10

1≤X≤9

Input

Output

Yes

No

Explanation:

• Test case-1: He can start at 7pm and finish by 10 pm. Therefore he can complete the
assignments.

• Test case-2: He cannot complete all the 3 assignments if he starts at 9 pm.

6. One hot summer day Suraj Kumar and his friend Avinash Yadav decided to buy a
watermelon. They chose the biggest and the ripest one weighing w kgs. They rushed
hostel, dying of thirst, and decided to divide the melon, however they faced a hard
problem. Both of them 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 an 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 meal 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 the positiveweight. Print YES, if the
boys can divide the watermelon into two parts or NO in the opposite case.

2
Input : 8

Output : Yes

6.Submission to codechef online judging platform- An example

• Login into codechef.com

• Take the problem https://www.codechef.com/problems/POPULATION

• Write your code on the right side panel. Run it. See if test cases correct. Then Submit.
And wait for the screen

The input format will always have no: of test cases as first input followed by the test
cases. In this problem the sample input is as below where 4 is the no: of test cases

Input :

312

222

418

10 1 10

Output

11

19
//The below for loop will read input no: of test cases 4 and
convert to int and range function generate numbers from 0
to 3.Loop will repeat for value of t from 0 to 3

for t in range(int(input())):

x,y,z = map(int,input().split())

[Give the logic of your code here]

3
Try submission of the below listed previous problems solved in the online judging platform
codechef

• https://www.codechef.com/problems/MINCOINS

• https://www.codechef.com/problems/REACHFAST

• https://www.codechef.com/problems/POLYBAGS

• https://www.codechef.com/problems/FRUITCHAAT

• https://www.codechef.com/problems/SONGS

• https://www.codechef.com/problems/WATERCOOLER1

• https://www.codechef.com/problems/WATERFILLING

• https://www.codechef.com/problems/ODDSUMPAIR

• https://www.codechef.com/problems/JASSIGNMENTS

• https://www.codechef.com/problems/SIXFRIENDS

4
Questions : Operator precedence. Predict the code output, Then run the below code and give
your explanation of how the computation gave the answer you got.
(a)

(b)

(c)

5
(d)

(e)

(f)

(g)

(h)

(i)

(j)

6
(k) Try the below two expressions and provide justification why answer differs and
explain the order of operator precedence.

result = 2 ** 3 + (5 * 4 - 12) % 7 // 2
result = 2 ** 3 + 5 * 4 - 12 % 7 // 2

You might also like