Resolved: Multiply sign using spyder!
Hi, I am already taking the python programmer boothcamp course and I had a little problem when I arrived to the loop section. Here is my problem:
When I try to make a multiplication with the sign ' * ', the computer send me back an 'n' times the number that I want to multiply. I think it is the best I can explain it. For example: If I try this
num_1 = input("Please enter a number between 1 and 12 :>") while (not num_1.isdigit()) or (int(num_1) < 1 or int(num_1) > 12):
print("You must write a number between 1 and 12")
num_1 = input("Please enter a number between 1 and 12 :>")
print("==============================")
print()
print(f'This is the {num_1} times table')
print()
for i in range(1,13):
print(f'{i} x {num_1} = {i * num_1}') it gets me: Please enter a number between 1 and 12 :>2
============================== This is the 2 times table 1 x 2 = 2
2 x 2 = 22
3 x 2 = 222
4 x 2 = 2222
5 x 2 = 22222
6 x 2 = 222222
7 x 2 = 2222222
8 x 2 = 22222222
9 x 2 = 222222222
10 x 2 = 2222222222
11 x 2 = 22222222222
12 x 2 = 222222222222 I am using spyder as the platform.
num_1 = input("Please enter a number between 1 and 12 :>") while (not num_1.isdigit()) or (int(num_1) < 1 or int(num_1) > 12):
print("You must write a number between 1 and 12")
num_1 = input("Please enter a number between 1 and 12 :>")
print("==============================")
print()
print(f'This is the {num_1} times table')
print()
for i in range(1,13):
print(f'{i} x {num_1} = {i * num_1}') it gets me: Please enter a number between 1 and 12 :>2
============================== This is the 2 times table 1 x 2 = 2
2 x 2 = 22
3 x 2 = 222
4 x 2 = 2222
5 x 2 = 22222
6 x 2 = 222222
7 x 2 = 2222222
8 x 2 = 22222222
9 x 2 = 222222222
10 x 2 = 2222222222
11 x 2 = 22222222222
12 x 2 = 222222222222 I am using spyder as the platform.
2 answers ( 1 marked as helpful)
Hi Octavio,
thanks for reaching out! The problem occurs, because your num_1 is a string, instead of an integer.
All you need to do is, after the user has selected a number and before you start the print statement, to convert your num_1 to an integer, like so:
num_1 = int(num_1)
and you should get the correct result
Best,
Eli
Thank you so much Eli, it was very helpful