Assignment
Assignment #: 5
Topic : Control Flow Statements
Selection:
Level 1: Easy
1. Take values of length and breadth of a rectangle from user and check if it is square
or not.
Sample test Cases
Test Cases Test Case1: Test Case 2:
Input 5, 3 7, 7
Output Not a Square Square
2. Write a program to get a number from the user and print whether it is positive,
negative or zero.
Sample test Cases
Test Cases Test Case1: Test Case 2:
Input 56 -235
Output Positive Negative
3. Write a program to find the mobile chosen is within the budget or not. To find the
budget mobiles is based on the below-mentioned criteria,
a) If the cost of the mobile chosen is less than or equal to 15000 then display it
as "Mobile chosen is within the budget"
b) If the cost of the mobile chosen is greater than 15000 then display it as
“Mobile chosen is beyond the budget”
Sample test Cases
Test Cases Test Case1: Test Case 2:
Input 12000 22000
Output Mobile chosen is within the budget Mobile chosen is beyond the budget
4. Write a program to check error in marks entry while user enters the marks in the
system. Consider Error as marks entered less than 0 and more than 100.
Sample test Cases
Test Cases Test Case1: Test Case 2: Test Case 3:
Input 83 101 -6
Output Valid entry Invalid entry Invalid entry
5. Write a program to check whether a kid is eligible for kinder garden school
admission. If a child is of age 4 or more then he/she is eligible.
Sample test Cases
Test Cases Test Case1: Test Case 2:
Input 4 2
Output Eligible Not Eligible
6. Write a program to read a Coordinate Point in a XY Coordinate System and
Determine its Quadrant.
Sample test Cases
Test Cases Test Case1: Test Case 2:
Input 4 2
Output Eligible Not Eligible
Level 2: Medium
1. There is a movie club for under 20 in the city, where the entry is age restricted.
Based on their age allow them into either ‘Cartoon Club’ or ‘Teens Club’.
Sample test Cases
Test Cases Test Case1: Test Case2: Test Case3: Test Case4:
Input 10 15 -10 25
Output Cartoon Club Teen Club Invalid Age Not Allowed
2. Write a program if an integer variable currentNumber is odd, change its value so
that it is now 3 times currentNumber plus 1, otherwise change its value so that it is
now half of currentNumber.
Sample test Cases
Test Cases Test Case1: Test Case2:
Input 17 26
Output 52 13
3. A person pays tax 10% if his income is more than 2.5 lacs for the amount excess
to 2.5 lacs. Person having annual income lesser than 2.5 lac is exempted from tax.
Write a program to implement it.
Sample test Cases
Test Cases Test Case1: Test Case2:
Input 200000 400000
Output You are exempted from tax Tax amount is 15000
4. Write a program to read date of birth as input & calculate the age.
Sample test Cases
Test Cases Test Case1:
Input 4 7 1989
Output 33 years 2 months 3 days (May differ. This result is calculated on 14-Sep-2022)
5. Write a program to calculate frequency of digits in a number.
Sample test Cases
Test Cases Test Case1:
Input 34593334
Output 3 occurs 4 times
4 occurs 2 times
5 occurs 1 times
9 occurs 1 times
6. During lockdown, ATMs were allowed to dispatch currencies in specific way. If
user enters the amount, which is not multiple of 500 transactions will be rejected.
If amount is 500 exactly, then 5 currencies of 100 will be dispatched by machine.
Sample test Cases
Test Cases Test Case1: Test Case2:
Input 500 300
Output please dispatch 5 notes of 100 please enter the amount multiple of 500
Level 3: Hard
1. A student will not be allowed to sit in exam if his/her attendance is less than
75%. Number of classes held, and the Number of classes attended are the inputs.
Display the attendance percentage and the eligibility of the student for the exam.
Allow the student to sit if he/she has medical cause. Ask user if he/she has medical
cause or not (‘Y' or 'N’) only when the attendance is lacking and print accordingly.
Sample test Cases
Test Cases Test Case1: Test Case2: Test Case3:
Input 100, 80 100, 60, ‘N’ 100, 70, ‘Y’
Output 80% Allowed 60% Not allowed 70% Allowed
2. Jessica teaches her students about how many days in a month, what is a leap
year and how to find it. Write a program to help her by saying the answer (number
of days in a month) to expect from the student for the given month number and the
year.
Sample test Cases
Test Cases Test Case1: Test Case2: Test Case3:
Input 2, 2016 7, 2020 2, 2019
Output February 2016 has 29 July 2020 has 31 days February 2019 has 28 days
days
3. During lockdown, ATMs were allowed to dispatch currencies in specific way. If
user enters the amount, which is not multiple of 500 transactions will be rejected.
If amount is 500 exactly, then 5 currencies of 100 will be dispatched by machine. If
amount is between 500 to 2000 you will get 500 in the form of 100s currencies, rest
500s currencies. If amount is greater than 2000, then 2000 currencies will be
dispatched and rest will be dispatched in the denomination of 500, last 500 will be
in the denomination of 100.
Sample test Cases
Test Cases Test Case1: Test Case2: Test Case3: Test Case4:
Input 400 500 1500 5000
Output please enter the 5 notes of 100 5 notes on 100 & 2 5 notes on 100, 2
amount multiple notes on 500 notes of 2000, 1
of 500 notes of 500
Iteration:
Level 1: Easy
1. Write a program to print the first N natural numbers if N is the input.
Sample test Cases
Test Cases Test Case1: Test Case2: Test Case3:
Input 5 7 11
Output 12345 1234567 1 2 3 4 5 6 7 8 9 10 11
2. Write a program to print the power of m raised to n.
Sample test Cases
Test Cases Test Case1: Test Case2:
Input 7, 5 4, 6
Output 16807 4096
3. Write a program to print the numbers from 1 to 20 other than the given number.
Input should be between 1 to 20.
Sample test Cases
Test Cases Test Case1: Test Case2: Test Case3:
Input 6 17 23
Output 1 2 3 4 5 7 8 9 10 11 12 1 2 3 4 5 7 8 9 10 11 12 13 Invalid Input
13 14 15 16 17 18 19 20 14 15 16 17 18 19 20
4. Write a program to print only the numbers divisible by 3 and 5 for a given number
from 1.
Sample test Cases
Test Cases Test Case1: Test Case2:
Input 20 40
Output 3 5 6 9 10 12 15 18 20 3 5 6 9 10 12 15 18 20 21 24 25 27 30 33 35
36 39 40
5. Write a program to print ‘odd’ or ‘even’ number series based on the given number.
That is if the input is an odd number, then it should generate the odd number series
from 1 to the given number inclusive. If it is even, then it should generate the series
from 2 to that number.
Sample test Cases
Test Cases Test Case1: Test Case2:
Input 13 16
Output 1 3 5 7 9 11 13 2 4 6 8 10 12 14 16
6. Write a program to print the following star patternSample test Cases
Test Cases Test Case1:
Input 5
Output *
* *
* **
* ***
* ****
Level 2: Medium
1. Write a program to read a number N. Find the sum of odd and even numbers from
1 to N numbers (inclusive).
Sample test Cases
Test Cases Test Case1: Test Case2:
Input 10 15
Output 25 30 64 56
2. Reina and Sierra were playing a game. Reina would give out number, and Sierra
must reverse the given number. Help Sierra by writing program to reverse the
number. Note that Reina should give a five-digit number.
Sample test Cases
Test Cases Test Case1: Test Case2:
Input 61987 1234
Output 78916 ‘Not a valid number’
3. Write a program to check whether the given number is prime or not.
Sample test Cases
Test Cases Test Case1: Test Case2:
Input 91 97
Output No Yes
4. Write a program to print all prime numbers between 1 and N(inclusive). N will be
the input.
Sample test Cases
Test Cases Test Case1:
Input 5
Output 235
5. Ann wanted to check her students’ knowledge on devisors. If she gives a number,
then students should say all the factors of that number. Write a program for this.
Sample test Cases
Test Cases Test Case1: Test Case2:
Input 18 36
Output 1 2 3 6 9 18 1 2 3 4 6 9 12 18 36
6. Read N and print Fibonacci series till N.
The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...
Sample test Cases
Test Cases Test Case1: Test Case2:
Input 50 100
Output 0, 1, 1, 2, 3, 5, 8, 13, 21, 34 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89
Level 3: Hard
1. Given a start number and end number, you need to display the numbers inclusive
but “ding” for every 5th number and “dong” for every 10th number.
Inputs: Starting number and Ending number
Outputs: Display “ding” for every 5th number and “dong” for every 10th number
Sample test Cases
Test Cases Test Case1:
Input 11, 40
Output 11 12 13 14 ding 16 17 18 19 dong 21 22 23 24 ding 26 27 28 29 dong 31
32 33 34 ding 36 37 38 39 dong
2. Ana planned to choose a four-digit lucky number for his car. Her lucky numbers
are 3, 5 and 7. Help her to find the car number, whose sum is divisible by 3 or 5 or
7. Provide a valid car number, fails to provide a valid input then display that number
is not a valid car number.
Sample test Cases
Test Cases Test Case1: Test Case2: Test Case3:
Input 1234 1214 14
Output Can be my car number Cannot be my car number It is not a valid car
number
3. Danny teaches his student to find the factorial of a number. He wanted to test the
understanding of the student. For that, he provides a number. He wants the students
to tell him that number is a factorial of which number. Help the student by writing
a program to do this. Note that the input should be a number greater than zero. If
the input is less than or equal to zero, the output should be “Invalid Input”. Also, if
the input provided is not exactly the factorial of a number, say, the input provided
is 122, which is not a perfect factorial of a number, it should return “Sorry. The
given number is not a perfect factorial”.
Sample test Cases
Test Cases Test Case1: Test Case2: Test Case3:
Input 5040 0 750
Output 7 Invalid input Sorry. The given
number is not a perfect
factorial