Robotics & Artificial Intelligence
A nested loop refers to a loop inside another loop. This is often used when you need to perform operations that involve multi-dimensional data or multiple conditions.
Write Python code to print the multiplication table for numbers from 1 to 5.
Python Control Flow
3 Likes
Answer
for i in range(1, 6):
for j in range(1, 11):
print(i, "x", j, "=", i * j)
print()Output
1 x 1 = 1
1 x 2 = 2
1 x 3 = 3
1 x 4 = 4
1 x 5 = 5
1 x 6 = 6
1 x 7 = 7
1 x 8 = 8
1 x 9 = 9
1 x 10 = 10
2 x 1 = 2
2 x 2 = 4
2 x 3 = 6
2 x 4 = 8
2 x 5 = 10
2 x 6 = 12
2 x 7 = 14
2 x 8 = 16
2 x 9 = 18
2 x 10 = 20
3 x 1 = 3
3 x 2 = 6
3 x 3 = 9
3 x 4 = 12
3 x 5 = 15
3 x 6 = 18
3 x 7 = 21
3 x 8 = 24
3 x 9 = 27
3 x 10 = 30
4 x 1 = 4
4 x 2 = 8
4 x 3 = 12
4 x 4 = 16
4 x 5 = 20
4 x 6 = 24
4 x 7 = 28
4 x 8 = 32
4 x 9 = 36
4 x 10 = 40
5 x 1 = 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
Answered By
3 Likes
Related Questions
What is a dictionary in Python?
- A collection of ordered and immutable elements
- A collection of unordered, changeable, and indexed key-value pairs
- A collection of unique elements
- A collection of ordered values with no keys
Python allows repetitive execution of a block of code through loops. The two primary loops in Python are for and while. You may use the range() function with a for loop to iterate over a sequence of numbers.
Write Python code that calculates the sum of all even numbers between 1 and 100 using for loop.
What is the purpose of the 'in' operator in Python?
- To check if a value exists in a sequence
- To start a loop
- To create a function
- To define a variable
What is the purpose of the 'pass' statement in Python?
- It terminates a loop when a condition is met
- It skips the current iteration of a loop
- It serves as a placeholder, allowing code to be syntactically correct while leaving the body empty
- It repeats the current iteration in a loop