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 trialDon Diurba
104 PointsPython Basics, Correct Errors, Challenge Task 1 of 1. I need help with details on understanding how to do this task.
How do I do the task?? Can you give examples.
print("Hello")
print(name)
print("Let's do some math!")
print(5 + "a")
print("Thanks for playing along!')
2 Answers
Haider Ali
Python Development Techdegree Graduate 24,728 PointsHi there. This challenge asks you to correct anything which would lead to an error. There are a couple of mistakes here which you need to fix:
print("Hello")
name = 'Haider' #name variable isn't defined so you need to define it
print(name)
print("Let's do some math!")
print(str(5) + "a") #cannot add string and integer so need to convert 5 to a string
print("Thanks for playing along!") #quotation marks at beginning and end do not match and should be the same like this
Thanks, Haider.
Tushar Singh
Courses Plus Student 8,692 PointsThanks man! Actually I do have 1 question, probably a stupid question. I started Python Track, after completing Python Basics, I am on the second-course, i.e, Python Collections. Now here comes the problem, I have to refer the forums for solutions again and again for coding challenges and I hate this part(when I can't solve the particular prob-really bugs me). I don't know what I am doing wrong. Sorry I din't ask the question yet :p So , what should I do now? I mean get back to Python Basics? or go on with the flow in a hope that it will make sense after sometime ?:D
Haider Ali
Python Development Techdegree Graduate 24,728 PointsHi there again Tushar, sorry for the late reply. If you do not fully understand a code challenge or cannot seem to solve it, I would advise that you go back and watch the previous video. If you still do not understand where you are going wrong, feel free to post here on the forum and there are many people willing to help. Also, the community here at treehouse is amazingly helpful and you are likely to get your question answered soon after posting it. :)
Tushar Singh
Courses Plus Student 8,692 PointsTushar Singh
Courses Plus Student 8,692 Points@ haider
print(str(5) + "a") #cannot add string and integer so need to convert 5 to a string
Can't I just put the number 5 in quotes to make a string? If yes, it dosen't work. print("5" + "a") after all it's not a number anymore, I don't know about the syntax so I may be wrong; just trying to use common sense I guess.
Second thing if I define a variable a = 2 Are these two functions(sorry if that's not what it is called) same? 1) print(5+a) 2)print(5+"a")
Haider Ali
Python Development Techdegree Graduate 24,728 PointsHaider Ali
Python Development Techdegree Graduate 24,728 PointsHey Tushar, I have had a look at what you said. In the challenge, if you write
print("5" + "a")
, it should pass if you have corrected all of the other mistakes. Also, answering your second question, the two function calls are not the same. Here is what each of them do:print(5 + a)
When calling this, python will add 5 to the whatever the value of the variable
a
is and print it to the screen. Sincea
is equal to 2, when you run this code it will print the number 7.print(5 + "a")
This on the other hand will give you a
TypeError
. This is because this call is trying to add a string and a number together. Python does not allow you to do this as if you are going to add 2 things together they must be of the same Data Type If there are quote marks around anything, it makes it a string.I hope this has helped, please comment again if you have any further questions. :)
Thanks,
Haider