In: Computer Science
This is in Python:
Alter your code for previous Do It Now problem, with the change that the row should only be printed by the second number that the user enters. For example, the user enters two numbers of 5 and 7 for the two input lines in the code, and the following will be printed:
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
*Previous Code that question refers to!*
Write a code to ask a number (one digit) from the user and prints the respective row of the multiplication table. For example, if the user enters 5, the following lines will be printed. Note that, if the user enters any number outside the range of 1-9, the program should display an error message.
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
num = int(input('Please enter the number : '));
while(num<1 or num>9):
num = int(input('Incorrect value entered, please re-enter : '));
for i in range(1,10):
print(num,' x ',i,' = ',num*i);
//pls provide +ve rating,thanks!
num = int(input('Please enter the number : '));
while(num<1 or num>9):
num = int(input('Incorrect value entered, please re-enter : '));
limit = int(input('Please enter the limit : '));
while(limit<1 or limit>9):
limit = int(input('Incorrect value entered, please re-enter : '));
for i in range(1,limit+1):
print(num,' x ',i,' = ',num*i);
#################################
#output
Please enter the number : 5
Please enter the limit : 7
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
//screenshot