0% found this document useful (0 votes)
3 views5 pages

Day 16 Python answers_59613207_2025_04_27_17_29

Uploaded by

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

Day 16 Python answers_59613207_2025_04_27_17_29

Uploaded by

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

HPSC PGT(CS)- Python Subjective Series

Day 16
Syllabus Coverage

Flow of Control

- Use of indentation.

- Sequential, conditional, and iterative flow control.

- Conditional statements: `if`, `if-else`, `if-elif-else`.

- Simple programs: absolute value, sorting 3 numbers, divisibility of a number.

- Iterative statements: `for` loop, `while` loop, `range` function.

- Flowcharts for loops.

- `break` and `continue` statements, nested loops.

- Suggested programs: generating patterns, summation of series, factorial of a number.

Program of the day:


1. Write a program that prints numbers from 1 to 100 but skips multiples of 2,3 and 5
5M
2. Write a program to print the multiplication table (upto 10) of a given number 5 M

1. Program to Print Numbers from 1 to 100, Skipping Multiples of 2, 3, and 5

Program:

for num in range(1, 101):

if num % 2 == 0 or num % 3 == 0 or num % 5 == 0:

continue

print(num)

Output:

11
13

17

19

23

29

31

37

41

43

47

49

53

59

61

67

71

73

77

79

83

89

91

97

2. Program to Print Multiplication Table (Up to 10) of a Given Number

Program:

num = int(input("Enter a number: "))


for i in range(1, 11):

print(num, "x", i, "=", num * i)

Output (for input 5):

5x1=5

5 x 2 = 10

5 x 3 = 15

5 x 4 = 20

5 x 5 = 25

5 x 6 = 30

5 x 7 = 35

5 x 8 = 40

5 x 9 = 45

5 x 10 = 50

Jumbo Program of the day:


Print an hourglass pattern with numbers:

12345

2345

345

45

45

345

2345

12345
Python program to print the hourglass pattern :

n=5

# Upper half of the hourglass

for i in range(n):

# Print leading spaces

print(' ' * i, end='')

# Print numbers

for j in range(i + 1, n + 1):

print(j, end=' ')

print()

# Lower half of the hourglass

for i in range(n - 2, -1, -1):

# Print leading spaces

print(' ' * i, end='')

# Print numbers

for j in range(i + 1, n + 1):

print(j, end=' ')

print()

Explanation:

1. Upper Half:

o The outer loop runs from i = 0 to i = 4 (for n = 5).

o ' ' * i adds increasing indentation.

o The inner loop prints numbers from i + 1 to n (e.g., for i = 0, it prints 1 2 3 4


5).

2. Lower Half:

o The outer loop runs backward from i = 3 to i = 0.

o ' ' * i adds decreasing indentation.

o The inner loop again prints numbers from i + 1 to n (e.g., for i = 1, it prints 2 3
4 5).

Output:
12345

2345

345

45

45

345

2345

12345

You might also like