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
Harsh Kumar Woike
204 Pointsthis code is not compiling.. i copied from the video. but still not happening
user_string = input("what's your word? ")
user_num = input(what's your number? ")
try:
our_num = int(user_num)
except:
our_num = float(user_num)
if not '.' in user_num:
print(user_string[our_num])
else:
ratio = =round{len(user_string)*user_num}
print(user_string[ratio])
3 Answers
Chris Freeman
Treehouse Moderator 68,468 PointsThere are just a few syntax errors:
user_string = input("what's your word? ")
user_num = input("what's your number? ") #<-- missing open quote mark
try:
our_num = int(user_num)
except:
our_num = float(user_num)
if not '.' in user_num:
print(user_string[our_num])
else:
ratio = round(len(user_string)*user_num) #<-- remove extra = sign, use {} instead of {}, adjust indent
print(user_string[ratio])
C H
6,587 PointsWhich video? I'm not sure what you're trying to do. I noticed a forgotten quotation mark and some of the usage of brackets/groupings don't make sense unless you're working with dictionaries or lists.
user_string = input("what's your word? ")
#added quotation mark
user_num = input("what's your number? ")
try:
our_num = int(user_num)
except:
our_num = float(user_num)
if '.' not in user_num:
#not sure what you want to print, but to print the word and number it's like this
print(user_string + user_num)
else:
#don't use curly brackets here
ratio = round(len(user_string) * our_num)
print(user_string + str(ratio))
jasonleonhard
3,424 PointsFYI: Python is "interpreted", not "compiled".
Not to confuse you, but to be clear, there are exceptions to this, such as Jython compiles into Java byte code, or the RPython language can be compiled to C, Java bytecode,