
![]() |
@wtf | |
(Multiplication tables & pattern printing) |
||
1
Replies
9
Views
2 Bookmarks
|
![]() |
@wtf | 15 days |
Today, Let’s move on to the next topic in the Python Coding Challenge: *Day 7: Loops in Python (for and while)* Loops are one of the most powerful tools in programming. They help us repeat tasks without writing repetitive code. *for Loop* Use a for loop when you know how many times you want to repeat something. for i in range(5): print(i) *Output* : 0 1 2 3 4 range(5) creates a sequence from 0 to 4 i takes each value one by one *while Loop* Use a while loop when you want to repeat until a condition is no longer true. count = 1 while count = 5: print(count) count += 1 *Output* : 1 2 3 4 5 *Mini Projects to Practice* *1. Multiplication Table Generator* num = int(input(Enter a number: )) for i in range(1, 11): print(fnum x i = num * i) *This lets users generate the multiplication table of any number.* *2. Pattern Printer (Staircase of Stars)* rows = 5 for i in range(1, rows + 1): print(* * i) *Output:* * ** *** **** ***** *Great intro to nested logic and string multiplication.* |
||


