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 Python Basics (Retired) Things That Count Basic Numbers

Welby Obeng
Welby Obeng
20,340 Points

why ValueError: invalid literal for int() with base 10: 'How many?

Take a look at my code below. Below that is the error I'm getting. Why is that? it worked for the instructor but not me. It's the same code. Am I missing something?

input_string = ("What sting do you want to use? ")
input_int = ("How many times should I repeat it? ")

print(input_string * int(input_int))

treehouse:~/workspace$ python string_mutiply.py

Traceback (most recent call last):                                                                                                                                                               
  File "string_mutiply.py", line 4, in <module>                                                                                                                                                  
    print(input_string * int(input_int))                                                                                                                                                         
ValueError: invalid literal for int() with base 10: 'How many times should I repeat it? '   

1 Answer

Mikael Enarsson
Mikael Enarsson
7,056 Points

You have to use the input() function to get the input from the user, so your code should look like this:

input_string = input("What sting do you want to use? ")
input_int = input("How many times should I repeat it? ")

print(input_string * int(input_int))

What your code does is assign the string How many times should I repeat it? to input_int, which can't be casted to an int.

I hope this helps ^^