Q1.
Print first 25 whole numbers one-by-one, each in a new line.
Write this program using while loop.
Q2.
Print all even numbers between 4 and 60, in a single line separated by a space in between.
Write this program using for loop.
Q3.
Print all odd numbers between 1 and 50 in reverse order.
Write this program using both while and for loop.
Q4.
Write a program to print all the numbers that are not divisible by 4, between 1 and 50.
Write this program using both while and for loop.
Q5.
Write a program that -
I.
Prints the multiplication table of 7.
II.
Asks the user to enter a number and prints the multiplication table of that number.
Q6.
What will be the output of the following programs?
You have to predict the output result without running/executing the code.
I.
count = 20 while count >= 10: print(count, end=' ') count -= 1 print("\nEnd of Loop")II.
for i in range(10, 0, -2): print(i) print("\nEnd of Loop")III.
count = 1 while count <= 10: print(count) print("\nEnd of Loop")IV.
for i in range(10, 0): print(i, end=' ') print("\nEnd of Loop")V.
count = 15 while count <= 10: count += 1 print(count) print("End of Loop")VI.
for i in range(1, 25, 4): print(i, end=' ') print("\nEnd of Loop")VII.
print ("start") for i in range(0): print (i) print ("end")
Q7.
A local weather station logs the rainfall (in mm) for each month of the year. Write a program that:
- Prompts the user to enter the rainfall for each of the 12 months.
- Calculates and displays the total rainfall and the average rainfall per month.
Expected Output
Enter rainfall for Month 1 (in mm): 100
Enter rainfall for Month 2 (in mm): 80
Enter rainfall for Month 3 (in mm): 90
Enter rainfall for Month 4 (in mm): 75
Enter rainfall for Month 5 (in mm): 60
Enter rainfall for Month 6 (in mm): 55
Enter rainfall for Month 7 (in mm): 40
Enter rainfall for Month 8 (in mm): 45
Enter rainfall for Month 9 (in mm): 70
Enter rainfall for Month 10 (in mm): 85
Enter rainfall for Month 11 (in mm): 95
Enter rainfall for Month 12 (in mm): 110
Total rainfall for the year: 905 mm
Average monthly rainfall: 75.42 mmQ8.
Fizz Buzz is a simple math game used to teach children about divisibility. It is also sometimes used as an interview question to assess basic programming skills. The rules of the game are simple: Starting at 1, and counting upward, replace any number divisible only by three with the word “fizz”, any number only divisible by five with the word “buzz”, and any number divisible by both 3 and 5 with the word “fizzbuzz”.)
Take 2 numbers as user input and then print all the numbers starting from first given number, incrementing one by one, to second given number at last, but for any number divisible only by 3 print the word “fizz”, any number only divisible by 5 print the word “buzz” and any number divisible by both 3 and 5 print the word “fizzbuzz”.
Expected Output
Enter first number: 9 // user input
Enter Second number: 28 // user input
fizz
buzz
11
fizz
13
14
fizzbuzz
16
17
fizz
19
buzz
fizz
22
.
.
.
28Q9.
What will be the output of the following programs?
You have to predict the output result without running/executing the code.
I.
count = 0 while count < 10: count += 1 if count % 3 == 0: continue print(count, end=' ') print("\nEnd of Loop")II.
for i in range(-3, 5): print(i, end=' ') if i / 2 == 1: break print("\nEnd of Loop")III.
for i in range(-5, 5): if ((i + i) >= (i * i)): continue print(i, end=' ') print("\nEnd of Loop")IV.
count = 1 while count <= 10: print(count, end=' ') if count == 3: break count += 1 else: print("\nEnd of Loop")V. (Adv.)
i = 50 while (i > 0 or (i + i == i * i)): print(i, end=' ') if i % 6 == 0: continue i -= 4 print("\nEnd of Loop")VI.
i = -5 while (i <= 0): print(i, end=' ') if i % 2 == 0: i = 0 i += 1 else: print("\nThe Loop is Over")VII.
for i in range(-5, 0): print(i, end=' ') if i % 2 == 0: i = 0 else: print("\nThe Loop is Over")
Q10.
You need a quick black-and-white checkerboard background for an old-school game screen. For it, write a program that asks the user for the board size N (an even number) and prints an NxN checkerboard of X and O characters, alternating each cell and each row.
Expected Output:
Enter board size (even number): 6 // user input
X O X O X O
O X O X O X
X O X O X O
O X O X O X
X O X O X O
O X O X O XQ11.
At a grocery checkout, the cashier enters each item’s price one by one. Write a program that:
- Keeps on asking the user for the price of the next item.
- Stops when the user enters 0 (indicating there are no more items).
- Prints the total of all the entered prices as a bill.
Expected Output
Enter price of item (or 0 to exit): 120 // user input
Enter price of item (or 0 to exit): 85 // user input
Enter price of item (or 0 to exit): 40 // user input
Enter price of item (or 0 to exit): 55 // user input
Enter price of item (or 0 to exit): 0 // user input
Total Bill: rs.300Q12.
A fitness app asks the user each day how many steps they walked, for a 7-day challenge. Write a program that:
- Asks the user - the step count for each day of the week.
- Counts how many days the user met or exceeded a target of 10,000 steps.
- After the week, reports the number of goal-met days.
Expected Output
Day 1 steps: 12000
Day 2 steps: 8000
Day 3 steps: 10000
Day 4 steps: 15000
Day 5 steps: 5000
Day 6 steps: 10000
Day 7 steps: 11000
You met your 10,000 steps goal on 5 out of 7 days.Q13. (Adv.)
A popular music festival is happening in town, and the organizer has invited N different bands to perform on the main stage. Since the event has only one stage, the performances will happen one after the other — no two bands can perform at the same time.
Now, the organizer wants to explore all the possible ways these bands could be scheduled throughout the day. This is important because the sequence in which the bands perform can impact the audience experience, energy levels, and crowd engagement.
For example, should the high-energy band go first, or last? Should the acoustic group follow the rock band, or should they go earlier? To make these decisions wisely, the organizer first wants to know: “In how many different ways can I arrange the performance order for today’s bands?”
Write a program that:
- Asks the organizer about how many bands are performing today?
- Calculates and displays the total number of possible lineups (schedules).
Expected Output
// case 1
Enter the number of bands:: 4 // user input
Total possible lineups: 24
// case 2
Enter the number of bands:: 6 // user input
Total possible lineups: 720Q14.
A new café wants a big, eye-catching sign around its name. To help them, write a program that asks the user for the width and height of the sign, then draw a rectangular border of * characters of that size. The inside should be blank.
Expected Output:
Enter width: 10 // user input
Enter height: 5 // user input
* * * * * * * * * *
* *
* *
* *
* * * * * * * * * *Q15.
At an event entrance, the staff record the ages of attendees. The survey wants to know how many are minors (< 18) and how many are adults (≥ 18). Write a program that:
- That first asks for the number of attendees to survey and then asks for each attendee’s age.
- Keeps counts of both minors and adults.
- Displays both counts at the end.
Expected Output
How many attendees to survey: 5
Enter age of attendee 1: 16
Enter age of attendee 2: 20
Enter age of attendee 3: 18
Enter age of attendee 4: 15
Enter age of attendee 5: 30
Survey Results:
Minors (under 18): 3
Adults (18 and over): 2Q16.
A coach wants a quick strike-rate report for every batsman in a small squad, each facing a fixed number of balls. To solve this problem, write a program that:
Asks how many batsmen are there in the squad.
Asks how many balls each batsman faced.
For each batsman, asks how many runs they scored on each ball.
Then calculates and prints, the total runs scored and the strike rate for each batsman (Runs/Balls * 100).
batting strike-rate = (total runs scored / total balls faced) * 100
Expected Output
Enter number of batsmen in the squad: 3
Enter number of balls faced by each batsman: 6
--- Squad Strike-Rate Report ---
Runs scored by batsman-1 on ball 1: 1
Runs scored by batsman-1 on ball 2: 4
Runs scored by batsman-1 on ball 3: 0
Runs scored by batsman-1 on ball 4: 2
Runs scored by batsman-1 on ball 5: 3
Runs scored by batsman-1 on ball 6: 0
Batsman-1: Total Runs: 10, Strike Rate: 166.67%
Runs scored by batsman-2 on ball 1: 0
Runs scored by batsman-2 on ball 2: 2
Runs scored by batsman-2 on ball 3: 6
Runs scored by batsman-2 on ball 4: 4
Runs scored by batsman-2 on ball 5: 2
Runs scored by batsman-2 on ball 6: 4
Batsman-2: Total Runs: 18, Strike Rate: 300.0%
Runs scored by batsman-3 on ball 1: 4
Runs scored by batsman-3 on ball 2: 1
Runs scored by batsman-3 on ball 3: 0
Runs scored by batsman-3 on ball 4: 0
Runs scored by batsman-3 on ball 5: 2
Runs scored by batsman-3 on ball 6: 1
Batsman-3: Total Runs: 8, Strike Rate: 133.33%Q17. (Adv.)
A fruit wholesaler receives apple crates every X days and orange crates every Y days. Each apple delivery brings A crates and each orange delivery brings B crates. The wholesaler stores all incoming crates and wants to pack mixed baskets so that every basket has the same number of apple and orange crates, using up the entire stock on one of the pack-days.
To solve the fruit wholesaler’s problem, write a program that asks the user to enter:
- Days between apple deliveries -
X - Number of apple crates per delivery -
A - Days between orange deliveries -
Y - Number of orange crates per delivery -
BThen calculate and display: - The maximum crates per basket (the largest equal number of apple and orange crates you can pack into each basket without leftovers).
- The days until the next full pack-day (after how many days the wholesaler will have exactly matching totals of stored apples and oranges to pack into those baskets).
Expected Output
// case 1
Enter apple delivery interval (days): 12
Enter apple crates per delivery: 36
Enter orange delivery interval (days): 15
Enter orange crates per delivery: 45
Maximum crates per basket: 9
Next matching delivery in: 60 days
// case 2
Enter apple delivery interval (days): 9
Enter apple crates per delivery: 25
Enter orange delivery interval (days): 6
Enter orange crates per delivery: 10
Maximum crates per basket: 5
Next matching delivery in: 18 days