V.Vidhya Logo

V.Vidhya

Operators


Q1.

BEG

Write a program to calculate the perimeter and the area of a rectangle. Take the length and the width of a rectangle from user and then prints the value of perimeter and area of that given rectangle.

Expected Output:

Enter the length of a rectangle: 10   // user input
Enter the width of a rectangle: 5   // user input

Perimeter: 30
Area: 50

// Perimeter = 2 * (l + w) = 2 * (10 + 5) = 30
// Area = l * w = 10 * 5 = 50

Q2.

What will be the output of the following programs?

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


Q3.

INT

There are 10 seats placed in a circle for an event, numbered from 1 to 10. People are arriving and standing in a waiting line (queue). Each person is given a seat based on their position in the line.

Write a program where the user enters their position in the waiting line (queue) and the program tells them which seat number they will get.

(For e.g. if someone is 11th in line, they should get seat 1 again because the seats are arranged in a circle. If someone is 12th, they get seat 2 and so on.)

Expected Output:

Enter your queue number: 23   // user input

Your seat number is: 3

Q4.

What will be the output of the following programs?

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


Q5.

BEG

Write a program that takes the cost of any 3 food items from the user (e.g. a packet of biscuit, a packet of waffer, an icecream cone) and then -

Expected Output:

Enter the cost of 3 food items: 50 20 60   // user input
Total Cost: 130
GST Amount : 23.4
Total Bill: 153.4

// Total Cost = 50 + 20 + 60 = 130
// GST Amount = Total Cost * 18 / 100 = 130 * 18 / 100 = 23.4
// Total Bill = Total Cost + GST Amount = 130 + 23.4 = 153.4

Q6.

BEG

Write a program that takes a value of radius from user, then find the circumference and area of a circle for a given radius.

Take 3.14 as the value of pi.

Expected Output:

Enter the value of radius: 5   // user input

Circumference: 31.4
Area: 78.5

// Circumference = 2 * pi * r = 2 * 3.14 * 5 = 31.4
// Area = pi * r * r = 3.14 * 5 * 5 = 78.5

Q7.

BEG

Write a program that takes a value of temperature in Celsius from user, then convert it into Kelvin and Fahrenheit.

The formulas for Celsius to Kelvin and Celsius to Fahrenheit are -

Expected Output:

Enter the value of temperature in Celsius: 30   // user input
temperature in Kelvin: 303
temperature in Fahrenheit: 86

// Kelvin = Celsius + 273 = 30 + 273 = 303
// Fahrenheit = 9/5 * Celsius + 32 = 9/5 * 30 + 32 = 86

Q8.

INT

You’re helping a government planning department analyze how a country’s population is expected to grow over time. Based on the current population, an estimated annual growth rate and a time period in years, you need to calculate what the population will be at the end of that period.

Population growth can be calculated by looking at the change in population over time. The formula for population growth is -

pt = p0 x (1 + r)t

Where,

Expected Output:

Enter the initial population (in crores): 142   // user input
Enter the rate of growth (in %): 0.875   // user input
Enter the time (in years): 5   // user input

Total population after given time (in crores): 148.322

Q9.

What will be the output of the following programs?

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


Q10.

BEG

A bank wants to alert its customers when their daily balance swing is large.

Expected Output:

// case 1
Enter opening balance (rs.): 2500.00   // user input
Enter closing balance (rs.): 1200.75   // user input

Alert! Your balance swung by rs.1299.25 today.

// case 2
Enter opening balance (rs.): 1300.00   // user input
Enter closing balance (rs.): 2600.75   // user input

Alert! Your balance swung by rs.1300.75 today.

Q11.

BEG

Your car’s onboard computer needs a quick summary of mileage. Write a program that -

Display the calculated result rounded to two decimal places.

Expected Output:

Enter distance travelled (km): 512.3   // user input
Enter fuel used (L): 36.8   // user input

Your fuel efficiency is 13.92 km/L.

Q12.

ADV

Consider the following division and remainder operations, and try to predict the result.

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

  1. 10 / 3
  2. 10.0 / 3.0
  3. 10 // 3
  4. 10 // 3.0
  5. 10 // -3
  6. -10 // -3
  7. 10 % 3
  8. 10.0 % 3
  9. -10 % 3
  10. 10 % -3

Q13.

INT

A workshop organizer needs to make a system to determine at what hour a workshop ends on a 12-hour clock, given its start time and duration. Write a Python program that -

Don’t worry about AM/PM for now - just work with the clock numbers.

Expected Output:

Enter the workshop starting time (1-12): 11   // user input
Enter the workshop duration (in hours): 3   // user input

The workshop will end at 2.

Prev Post
Variables, Data Types & User I/O
Next Post
Conditionals