0% found this document useful (0 votes)
25 views4 pages

Flow of Control (Practice Questions)

Uploaded by

patodiabarsha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views4 pages

Flow of Control (Practice Questions)

Uploaded by

patodiabarsha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

WHILE LOOP

1. Print Numbers 1 to 10: Write a program using a while loop to print numbers from 1 to
10.
2. Sum of First N Natural Numbers: Take a number n as input and calculate the sum of
numbers from 1 to n using a while loop.
3. Even Numbers from 1 to 20: Print all even numbers between 1 and 20 using a while
loop.
4. Odd Numbers from 1 to 20: Print all odd numbers between 1 and 20 using a while loop.
5. Reverse Counting: Take an integer n as input and print numbers from n to 1 using a
while loop.
6. Multiplication Table: Take a number as input and print its multiplication table up to 10
using a while loop.
7. Factorial Calculation: Write a program to calculate the factorial of a given number
using a while loop.
8. Reverse a Number: Ask the user to enter a number and print its reverse using a while
loop.
9. Sum of Digits: Write a program to calculate the sum of digits of a given number using a
while loop.
10. Check for Palindrome Number: Write a program to check if a given number is a
palindrome using a while loop.

FOR LOOP

 Print Numbers 1 to 10: Write a program using a for loop to print numbers from 1 to 10.
 Sum of First N Natural Numbers: Take a number n as input and calculate the sum of
numbers from 1 to n using a for loop.
 Even Numbers from 1 to 20: Print all even numbers between 1 and 20 using a for loop.
 Odd Numbers from 1 to 20: Print all odd numbers between 1 and 20 using a for loop.
 Reverse Counting: Take an integer n as input and print numbers from n to 1 using a for
loop.
 Multiplication Table: Take a number as input and print its multiplication table up to 10
using a for loop.
 Factorial Calculation: Write a program to calculate the factorial of a given number
using a for loop.
 Reverse a Number: Ask the user to enter a number and print its reverse using a for loop.
 Sum of Digits: Write a program to calculate the sum of digits of a given number using a
for loop.
 Check for Palindrome Number: Write a program to check if a given number is a
palindrome using a for loop.
 Fibonacci Series: Print the Fibonacci series up to n terms using a for loop.
 Find the Smallest Divisor (Other than 1): Take a number as input and find its smallest
divisor greater than 1 using a for loop.
 Armstrong Number Check: Check if a given number is an Armstrong number using a
for loop.
 Prime Numbers in a Given Range: Take two numbers as input and print all prime
numbers between them using a for loop.
 Sum of Odd Numbers in a Range: Write a program to print the sum of all odd numbers
between two numbers a and b (inclusive) using a for loop.

JUMP STATEMENT

1. Write a program to print numbers from 1 to 10, but stop the loop if the number 7 is
reached.
2. Write a program to print all odd numbers between 1 and 20.

Hint: Use a for loop and a continue statement to skip even numbers.

3.Write a program to search for the character 'e' in the string "Hello, Python!" and stop the loop
when it is found.

Hint: Use a for loop and a break statement.

4.Write a program to iterate over a list of integers and print only the positive values.

Hint: Use a for loop and a continue statement to skip negative numbers.

5.Write a program to add numbers from 1 upwards until the sum exceeds 100, then stop the loop.

Hint: Use a while loop and a break statement to exit when the condition is met.

6.Write a program to print numbers from 1 to 10, but skip numbers 3 and 6.

Hint: Use a for loop and a continue statement.

7.Write a program to find and print the first number between 1 and 50 that is divisible by 9.

Hint: Use a for loop and a break statement.

8.Write a program to repeatedly ask for user input until the user types "quit".

Hint: Use a while loop and a break statement when the input is "quit".

9.Write a program to iterate through a string and print only the uppercase letters.

Hint: Use a for loop and a continue statement to skip lowercase letters.

10.Write a program to count and print the number of non-vowel characters in a given string.

Hint: Use a for loop and a continue statement to skip vowels.


SELECTION/CONDITION STATEMENT

1. Write a program that asks for a person's age and prints whether they are eligible to vote
(18 years or older).

Hint: Use an if-else statement.

2.Write a program that takes a student's score as input and prints their grade:

 90 and above: "A"


 80–89: "B"
 70–79: "C"
 60–69: "D"
 Below 60: "F"

Hint: Use if-elif-else statements.

3.Write a program that checks if a number is even or odd.

Hint: Use an if-else statement.

4.Write a program that checks if a number is positive, negative, or zero.

Hint: Use an if-elif-else statement.

5.Write a program that checks if a year is a leap year. A year is a leap year if:

 It is divisible by 4.
 If divisible by 100, it must also be divisible by 400.

Hint: Use nested if statements

6.Write a program that takes three sides of a triangle and prints:

 "Equilateral" if all sides are equal.


 "Isosceles" if exactly two sides are equal.
 "Scalene" if all sides are different.

7.Write a program that classifies a person based on age:

 "Child" if age is less than 12.


 "Teen" if age is between 12 and 18.
 "Adult" if age is between 19 and 60.
 "Senior" if age is above 60.

8.Write a program that takes a student's score and prints:


 "Excellent" if score is above 90.
 "Good" if score is between 75 and 90.
 "Average" if score is between 50 and 75.
 "Fail" if score is below 50.

Hint: Use nested if-else statements.

9.Write a program that checks if a number is:

 Positive and even.


 Positive and odd.
 Negative and even.
 Negative and odd.
 Zero.

Hint: Use nested if-else statements.

10.Write a program that simulates a login system:

 Ask for username.


 If username is correct, ask for password.
 If password is correct, print "Login successful".
 If password is incorrect, print "Incorrect password".
 If username is incorrect, print "Username not found".

Hint: Use nested if-else statements.

11.Write a program that classifies a person based on:

 Age (Child, Teen, Adult, Senior).


 Height (Short, Average, Tall).

Hint: Use nested if-else statements.

12.Write a program that classifies a student's performance based on:

 Subject (Math, Science, English).


 Grade (A, B, C, D, F).

Hint: Use nested if-else statements.

You might also like