Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
45 views

Python Exercises-Conditional Statements

The document provides Python exercises involving conditional statements and sorting numbers. It includes 21 exercises involving if/else statements, comparison operators, and sorting values. It also provides a sample electricity bill program that calculates charges based on usage tiers.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

Python Exercises-Conditional Statements

The document provides Python exercises involving conditional statements and sorting numbers. It includes 21 exercises involving if/else statements, comparison operators, and sorting values. It also provides a sample electricity bill program that calculates charges based on usage tiers.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Stage: C-11

Subject: Computer Science

Python Exercises Worksheet (Conditional Statements)

Write Java programs to perform the following tasks:

1. Find if given number is greater than 9.


2. Read marks and print if student has passed or failed.
3. Find greatest of two numbers.
4. Find if a person is eligible to vote or not.
5. Find if odd or even.
6. Determine if given number is positive, negative or zero.
7. Accept SP and CP and display if it is loss, gain or breakeven.
8. Find if given number is divisible by 5.
9. Find greatest of three numbers.
10. If the ages of Harry, Ron and Hermione are input through the keyboard, write a program to determine the
youngest of the three.
11. Accept the three sides of a triangle and display the type of triangle i.e. whether it equilateral, isosceles or scalene.
12. To check whether a triangle is valid or not, when the three angles of the triangle are entered through the keyboard.
13. Accept a number representing the week day and display the week name
a. Using if statement
b. Using CASE construct
14. Accept a number representing the month: (Use CASE construct only)
a. display the month name
b. display the number of days in the month
15. Accept two numbers and an arithmetic operator. Based on the operator, perform the corresponding arithmetic
operation and display the result.
16. Accept a number and display its absolute value.
17. Accept three numbers representing the constants of a quadratic equation and display the nature or roots (equal,
real and unequal, imaginary)
18. Accept a character from the user and display whether it is a vowel, consonant, special character or digit.
19. Accept year from the user and display whether it is a leap year or not.
20. Accept the coordinates of a point (x,y) and find out if it lies on the X-axis, Y-axis or on the origin (0,0).

21. Input three values a, b, and c and sort these three values in ascending order by comparing and
exchanging their values. At the end of the program a <= b <= c must hold. You can solve this exercise
with three if in minimum. Test your program with all six permutations of three different numbers.

Advanced Conditional Programs

The Electricity Board charges from their consumers according to the units consumed per month. The amount to
be paid as per the given tariff:
Units consumed Charges
Up to 100 units Rs.5.50/unit
For next 200 units Rs.6.50/unit
For next 300 units Rs.7.50/unit
More than 600 units Rs.8.50/unit

Write a program to input consumer’s name, consumer number and the units consumed. The program displays
the following information at the time of receiving the money receipt as:

Money Receipt

Consumer Number :
Consumer’s Name :
Units consumed :
Amount to be paid :

You might also like