The 365 Data Science team is proud to invite you to our own community forum. A very well built system to support your queries, questions and give the chance to show your knowledge and help others in their path of becoming Data Science specialists.
Ask
Anybody can ask a question
Answer
Anybody can answer
Vote
The best answers are voted up and moderated by our team

Multiply sign using spyder!

Multiply sign using spyder!

0
Votes
1
Answer

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. 

1 Answer

365 Team
0
Votes

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

×
Ready to Learn
Data Science?
50% OFF