V.Vidhya Logo

V.Vidhya

Conditionals


Q1.

Consider the following programs:

What will be the output for the programs given above?

You have to predict the output yourself without running/executing the code.

  1. Hi
  2. Bye
  3. Error
  4. None

Q2.

BEG

At a local bank, customers are allowed to withdraw money without any extra charge as long as the withdrawal amount is less than rs.1000 in a single day. However, if a customer withdraws rs.1000 or more in a day, a small transaction fee is applied. Write a program that asks the customer how much money they want to withdraw today and based on the amount, tells them whether a transaction fee will be applied or not.

Expected Output:

// case 1
Enter withdrawal amount: 750   // user input
A transaction fee will not be applied.

// case 2
Enter withdrawal amount: 2650   // user input
A transaction fee will be applied.

Q3.

What will be the output of the following programs?

You have to predict the output yourself without running/executing the code.


Q4.

BEG

At a stationery shop, pens are packed in boxes of five. Write a program that asks the user for the total number of pens they have and then tells the user whether all the pens will fit into complete boxes or how many pens will be left over after packing.

Expected Output:

// case 1
Enter the total number of pens: 20   // user input
All pens fit into complete boxes - no leftovers!

// case 2
Enter the total number of pens: 64   // user input
You have 4 pen(s) left unpacked.

Q5.

What will be the output of the following programs?

You have to predict the output yourself without running/executing the code.


Q6.

BEG

At the airport cargo counter, packages are checked based on their size. Instead of actual weight, they use a volumetric weight formula to decide if the package is too heavy to ship. Write a program that ask the user to enter the length, breadth, and height of the package in cm, then calculate the volumetric weight in kg and finally tells if the package is accepted for shipping or not.

Expected Output:

// case 1
Enter the length of the package (in cm): 40   // user input
Enter the breadth of the package (in cm): 30   // user input
Enter the height of the package (in cm): 20   // user input

Volumetric weight: 4.8 kg  
Package accepted for shipping.

// case 2
Enter the length of the package (in cm): 100   // user input
Enter the breadth of the package (in cm): 80   // user input
Enter the height of the package (in cm): 50   // user input

Volumetric weight: 80.0 kg  
Package too heavy for air shipping!

Q7.

What will be the output of the following programs?

You have to predict the output yourself without running/executing the code.


Q8.

BEG

Write a program that takes an integer from user and checks if that number is even or odd.

Expected Output:

Enter a number: 9   // user input

9 is an odd number.

Q9.

BEG

Write a program that asks the user to enter the color of a street light that is currently being shown. Based on the input, display the correct message accordingly:

Expected Output:

// case 1
Enter the street light color: red  // user input
STOP

// case 2
Enter the street light color: blue   // user input
None

Q10.

INT

At the college library, books can be borrowed and returned by students. To manage everything efficiently, they need a system to check students’ borrowing history and pending dues. Write a program that,

Write a program for this.

Expected Output:

// case 1
Did you borrow any book previously? (yes/no): no   // user input
You can borrow a new book. No pending returns.

// case 2
Did you borrow any book previously? (yes/no): yes   // user input
How many days ago did you borrow the book?: 10   // user input
Book returned within allowed time. You can borrow a new book.

// case 3
Did you borrow any book previously? (yes/no): yes   // user input
How many days ago did you borrow the book?: 20   // user input
Your book return is overdue. You have a pending fine of rs.6.
Please clear the fine before borrowing a new book.

Q11.

BEG

A college professor wants to make a student result declaration system. Write a program that takes student percentage as user input and gives student’s result status.

Expected Output:

Enter student percentage: 65   // user input

Result: Pass with Merit

Q12.

BEG

Create a system to calculate popcorn prices based on the bucket size customer asks for:

Here, the list for price per bucket-size is given:

Expected Output:

Enter the popcorn-bucket size: M   // user input

Price: 100

Q13.

BEG

At a city’s traffic control system, drivers are monitored for speed violations. The city has a strict speed policy - if a driver stays within the speed limit, they can continue without any fine. However, if they exceed the limit, fines are imposed depending on how much they overspeed.

Write a program that asks the driver for their current speed and informs them if they are safe or what fine they need to pay.

Expected Output:

// case 1
Enter your current speed (in km/h): 75   // user input
You have exceeded the speed limit. A fine of rs.500 is applicable.

// case 2
Enter your current speed (in km/h): 95   // user input
You have exceeded the speed limit. A fine of rs.1000 is applicable.

Q14.

BEG

For a good and safe paragliding experience as a beginner, certain weather conditions need to be met.

Write a program that checks if it’s a good condition for paragliding or not based on necessary weather parameters taken as user input .

Expected Output:

Is it raining? : false   // user input
Wind speeds (km/h) : 12   // user input

It's a good condition for paragliding.

Q15.

BEG

Create a program to make a mini-calculator.

Take 2 integer numbers and the operator sign as input from the user, then give the result based on those taken values.

All the arithmetic operators should be covered, i.e. + , - , * , / , %, ^ (power).

Expected Output:

Enter the first number : 3   // user input
Enter the second number : 5   // user input

Choose the operation you want to perform (+, -, *, /, %, ^): *   // user input

output: 5 * 3 = 15

Q16.

ADV

At the city’s electricity board, household electricity bills are calculated based on the number of units consumed in a month. The board follows a slab system where different rates apply based on consumption levels.

Write a program that asks the user to enter the total number of electricity units consumed for the month, then calculates and displays the final bill amount according to the following rules:

Expected Output:

// case 1
Enter total electricity units consumed: 150   // user input
Electricity Bill: rs.500

// First 100 units: 100 x rs.3 = rs.300, Next 50 units: 50 x rs.4 = rs.200
// Total = rs.300 + rs.200 = rs.500

// case 2
Enter total electricity units consumed: 250   // user input
Electricity Bill: rs.950

// First 100 units: 100 x rs.3 = rs.300, Next 100 units: 100 x rs.4 = rs.400
// Remaining 50 units: 50 x rs.5 = rs.250
// Total = rs.300 + rs.400 + rs.250 = rs.950

Q17.

INT

At an international airport’s travel help desk, travellers often want to know the value of their Indian Rupees (INR) in different currencies. Write a program that helps a traveller by converting their amount in INR into a currency of their choice.

Expected Output

Enter the amount in INR: 7000   // user input

Select the currency to convert to:
1 - US Dollar (USD)
2 - Euro (EUR)
3 - British Pound (GBP)
4 - Chinese Yuan (CNY)
5 - Russian Ruble (RUB)

Your choice (1-5): 2   // user input

Converted amount: 77 EUR

Prev Post
Operators
Next Post
Loops