Python Control Structures - Assignment Questions
Basic Level (10 Questions)
- Write a Python program to check if a number is positive, negative, or zero using
if
statement.
- Write a program to find the largest of two numbers using
if-else
.
- Write a program to print all numbers from 1 to 10 using a
while
loop.
- Print all even numbers between 1 and 20 using a
for
loop.
- Write a program to check whether a number is even or odd.
- Write a program to print the multiplication table of a given number using a
for
loop.
- Write a program to find the factorial of a number using a
while
loop.
- Write a program to print the first 10 natural numbers using a
for
loop.
- Write a program to find the sum of all numbers from 1 to n, where n is input from the user.
- Write a program to check if a character is a vowel or consonant using
if-else
.
Intermediate Level (10 Questions)
- Write a program to find the largest among three numbers using
if-elif-else
.
- Write a program to print all prime numbers between 1 and 100 using
for
loop and if
conditions.
- Write a program to calculate the sum of digits of a given number using a
while
loop.
- Write a program to reverse a given number using a
while
loop.
- Write a program to print a pyramid pattern of stars using nested
for
loops.
- Write a program to check if a string is a palindrome using
for
loop.
- Write a program to generate Fibonacci series up to n terms using a
while
loop.
- Write a program to find the GCD (Greatest Common Divisor) of two numbers using
while
loop.
- Write a program to find the factorial of a number using recursion (use
if-else
for base case).
- Write a program to count the number of vowels in a given string using a
for
loop.
Advanced Level (10 Questions)
- Write a program to print all Armstrong numbers between 100 and 999 using nested loops.
- Write a program to implement a basic calculator using
if-elif-else
for operations (+, -, *, /).
- Write a program to print Pascal’s triangle up to n rows using nested loops.
- Write a program to find the sum of even and odd numbers separately from a list of numbers.
- Write a program to merge two sorted lists into a single sorted list using loops.
- Write a program to simulate a number guessing game where the user has limited attempts.
- Write a program to print the pattern of numbers like:
1
12
123
1234
using nested loops.
- Write a program to find the first n prime numbers using loops.
- Write a program to remove duplicate elements from a list without using set().
- Write a program to check whether a given year is a leap year or not using control structures.