YirouC
YirouC

Reputation: 11

Python exponent operator and multiplication

I'm trying to get an exponential-multiply operation work but the output is not what i expected. It should be a simple operation where the programs takes in a number, and multiply by the 10³.

input: 9 expected output: 9000

actual output: 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999

This is my code:

num = input("Please enter a number:")
n1 = 10**3
output = n1*num
print(output)

Upvotes: 1

Views: 867

Answers (2)

Deep Bhatt
Deep Bhatt

Reputation: 313

Try this.

num = int(input("Please enter a number:"))
output = (10 ** 3) * num
print(output)

Upvotes: 0

Samwise
Samwise

Reputation: 71454

When you multiply a str by an int, the string repeats:

>>> "foobar" * 10
'foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar'

You're multiplying the string "9" by the number 1000, meaning you get a string of one thousand "9"s.

If you want to multiply the number 9 by the number 1000, that would look more like:

num = int(input("Please enter a number:"))
n1 = 10**3
print(n1*num)

Upvotes: 1

Related Questions