title | subtitle |
---|---|
Condition Statements practice |
Practice code 2 |
This Notebook Contains practice question for the note on Condition statements.
Try working online at:
Coding Ground - Tutorials Point
Online Compiler and Debugger
Q1: Write a program to get a number as input and print if it is odd or even.
Sample 1:
I/P: 10
O/P: Even
>**Sample 2:** I/P: 11 O/P: Odd
Q2: Write a program to get a number as input and check whether it is positive, negative or zero.
Sample 1:
I/P: 10
O/P: Positive
>**Sample 2:** I/P: 0 O/P: Zero
>**Sample 3:** I/P: -5 O/P: Negative
Q3: Write a program to get the mark of a student as input print his grade.
Condition:
mark < 0 or mark > 100: Invalid
90 < mark <= 100: O
80 < mark <= 90 : A+
70 < mark <= 80 : A
60 < mark <= 70 : B+
50 <= mark <= 60: B
0 <= mark < 50: Fail
Sample 1:
I/P: 85
O/P: A+
>**Sample 2:** I/P: 10 O/P: Fail
Q4: Write a program to get the age of the user and print if he is eligible to vote.
Condition: A person is eligible to vote if his/her age is greater than or equal to 18
Sample 1:
I/P: 10
O/P: Ineligible
>**Sample 2:** I/P: 27 O/P: Eligible
Q5: Code a simple Calculator.
Q6: Write a program to get an input from the user and print if it is a vowel or a consonant.
Q7: Write a program to two numbers and print the greatest of them.
Q8: Write a program to get three numbers and the print the greatest of them.
Q9: Write a program to check if a number is a perfect square or not.
Q10: The humidity (in percentage) and temperature (in celsius) value in a city is given as the input to the program. The program must print YES as the output if there is a possibility of rain. Else the program must print NO as the output. If one of the conditions given below is true then there is a possibility of rain.
Condition:
- Humidity > 90
- Temperature < 18
- Humidity > 70 and Temperature < 30
- Humidity > 60 and Temperature < 24
Q11: Write a program to get a year as input and print if it is a leap year or not.
A year is leap if it is either divisible 4 or 400 and not 100.