Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Why does the program output 33333333 if you enter three tickets and don't convert to integer? Three is an integer.

I understand it is necessary to convert to an integer. But intuitively, it seems like if you do not convert and the user enters 3, the program should still output $30, since 3 times 10 is 30.

1 Answer

When using input() in python it returns a string by default.

If you were to multiply a string

y = 'test'

x = y * 5

print(x)

It would equal 'testtesttesttesttest'

That is why you are seeing 3 repeated. If you don't convert your input to an int, it will assume it is a string and use standard string multiplication

Thank you