Saturday, October 29, 2022

Practice Question - Conditional Statement & Loop(for & while)

Practice Question
In [ ]:
 

Conditional Statements & Operators:

Q1. A program to find if the entered number is positive, negative or zero

Q2. WAP in python to find the largest of two numbers

Q3. WAP in python to find the largest of three numbers

Q4. WAP in python to check if a numbers is divible by both 5 and 10

Q5. WAP in python to check if a number is odd or even

Q6. WAP in python to find the grade from the percentage of marks. Use the following reference chart of grades:
percentage>=90 then A grade
percentage<90 but >=80 then B grade
percentage<80 but >=60 then C grade
percentage<60 but >=40 then D grade
percentage<40 then E grade

Q7. WAP in python to calculate the electricity bill by using the following citeria. Take the present and previous meter reading from the user.
unit   |   rate
1st 100  |   rs 2 per unit
Next 100  |   rs 5 per unit
after 200   |   rs 10 per unit

Q8. WAP in python to accept a number from 1 to 12 and display name of the month. Example: if 4 is entered then month should be april.

Q9.Write a program to check whether a person is eligible for voting or not.(A person who is minimum 18 years of age is eligible to vote in india)

Q10. A Zonet cable company decided to give bonus to employee.Take the years of work from the employee and display the percetage of bonus they are going to get. Use the following criteria to calculate the bonus :

if job years more than 10 years then 10% if job years is less than 10 years but more than or equal to 6 years then 8% and if job years is less than 6 years then 6%

Loop/Iteration:

For Loop

Q1. WAP to display first 20 numbers using a for loop.

Q2. WAP to display the first 10 even numbers using for loop.

Q3. WAP in python to input a number and print multiplication table of the number.

Q4. WAP in python to input a number and check if its prime or not

Q5. WAP in python to search for prime numbers from 15 till 25

Q6. WAP in python to input a multidigit number and display each digit of the number in a new line.

Q7. WAP in python to print the following diagram:

+
++
+++
++++
+++++

Q8. WAP in python to display first 10 fibonacii number .
example: 1 1 2 3 5 8 13 ...

Q9. WAP in python to input a multidigit number and find the sum of all the digits.

Q10. WAP in python to input a digit and print it in words.

While loop

Q1. WAP to display first 20 numbers using a while loop.

Q2. WAP to display the first 10 even numbers using for loop.

Q3. WAP in pythonto demonstrate an infinite loop(i.e. a loop that never terminates)

Q4. Wap in python to take a number as input and calculate its factorial.

Q5. WAP in python to input a number and check if it is armstrong number(i.e. if a 3 digit number is equal to the sum of the cubes of its each digit, then its a armstrong number)

Q6. WAP in python to input a multidigit number and find the sum of all the digits using while loop.

Q7. WAP in python to check if a number is prime using while loop.

Q8. Write a program to reverse the number accepted from user using while loop.

Q9. Write a program to reverse the number accepted from user using while loop.

Q10. Construct a menue driven calculator. i.e. the calculator terminates only when q is pressed:

  1. press c to calculate
  2. press q to quit
In [ ]:
 
Share: