..
Applying Knowledge - Class 6 (part 2)
Write a Python program that accepts a positive integer within the range of 0 to 10 (inclusive) and displays the multiplication table for that number from 1 to 10.
The input must be validated to ensure it is a number between 0 and 10 (inclusive). If the input is out of this range, the program will display the message INVALID VALUE and will prompt for the input again until a valid number is provided.
Once valid input is received, the program will display the multiplication table for the number entered, as demonstrated in the test case.
Input:
- A positive integer between 0 and 10 (inclusive).
Output:
- The multiplication table for this number, showing products from 1 to 10.
Sample Inputs/Outputs:
foo@bar:~$ py baz.py
-1
INVALID VALUE
20
INVALID VALUE
4
4x1=4
4x2=8
4x3=12
4x4=16
4x5=20
4x6=24
4x7=28
4x8=32
4x9=36
4x10=40
foo@bar:~$
foo@bar:~$ py baz.py
0
0x1=0
0x2=0
0x3=0
0x4=0
0x5=0
0x6=0
0x7=0
0x8=0
0x9=0
0x10=0
foo@bar:~$
SOLUTION:
while True:
x = int(input())
if 0 > x or x > 10:
print('VALOR INVÁLIDO')
else:
for y in range(1, 11):
print(f'{x}x{y}={x*y}')
break
for fun:
(func := lambda f, i=int(input()): (0 > i or i > 10) and (print("VALOR INVÁLIDO") == None) and (f(f, int(input())) == None) or (0 <= i <= 10) and print("\n".join(f"{i}x{x}={i*x}" for x in range(1, 11))))(func)