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 My Solution

my solution

verb = input("Please enter a verb ")
noun = input("Please enter a noun ")
adjective = input("Please enter a adjective ")

print("I enjoy practice! I find it helps me to " + verb + " better.")
print("Without practice, my " + noun + " would probably not even work.")
print("My code is getting more " + adjective + " every single day!")

the instructor used "," but I used "+" what's the actual difference?

5 Answers

usually we coders tend to write code the way we first learnt it and so how you write your code will depend on who tough you your first code and in what way did he/she put it across to you. So all the formats are ok use the one you find convenient

print("HAPPY CODING FOLKS!")

Which one is best practice and why?

The best option would probably depend on the programmer and what he's normally used to using but as for me, I find using the placeholders({}) quiet easy to use and to understand. Especially when I need to revisit my code and check where I've used my variables and how I used them. I shun option 1 of concatenating strings and variables as using '+' comes with chances of making mistakes when placing the quotes and the '+' sign. Another quiet handy way of using variables in a print statement is to use f-strings. You get to use placeholders and not need to use the .format() method!

Example:

name = 'Tree'
surname = 'house'
print(f'{name}{house}.') 
name = "Tom"
age = 14
print(f"My name is {name}. I'm {age} years old.") 

Which one is best practice and why?

print("I enjoy practice! I find it helps me to " + verb + " better.")
print("Without practice, my " + noun + " would probably not even work.")
print("My code is getting more " + adjective + " every single day!")

OR

print("I enjoy practice! I find it helps me to", verb, "better.")
print("Without practice, my", noun, "would probably not even work.")
print("My code is getting more", adjective, "every single day!")

OR

print("I enjoy practice! I find it helps me to {} better.".format(verb))
print("Without practice, my {} would probably not even work.".format(noun))
print("My code is getting more {} every single day!".format(adjective))
Tsering Choedhen
Tsering Choedhen
1,051 Points

I am so happy to do it myself. I wanted to show my result here but i do not know how to paste my code in here. I am really enjoying this. Its like learning a new language but using basic english language.

Ams BM
Ams BM
5,898 Points

My solution using f string

verb_input = input("Please enter a verb: ")
noun_input = input("Please enter a noun: ")
adjective_input = input("Please enter a adjective: ")

str_one = f"I enjoy practice! I find it helps me to {verb_input} better."
str_two = f"Without practice, my {noun_input} would probably not even work"
str_three = f"My code is getting more {adjective_input} every single day!"

print(str_one)
print(str_two)
print(str_three)

I can just simply place the f sting inside the print() function.

print(f"I enjoy practice! I find it helps me to {verb_input} better.")
print(f"Without practice, my {noun_input} would probably not even work")
print(f"My code is getting more {adjective_input} every single day!")