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 Create a Mad Lib

Liam White
Liam White
1,969 Points

Print Statement

Why all the separate print statements? Can the f-string be executed under one print statement? Thank you!

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,454 Points

Hey Liam White, As long as you mind the newlines and add spaces where needed, the print statements can certainly be strung together within a single print statement. One advantage provided by separate print statements is the automatic newline ⏎ character. If strung together, newline characters (\n) would need to be inserted.

# orginial
print(f"I have a(n) {adjective1} idea for a program!")
print(f"It will watch {plural_noun2} and count how many times they {verb3}.")
print(f"I don't think it will {verb4} the world or anything, but I'm {adjective5} about it!")

# merged
print(f"I have a(n) {adjective1} idea for a program!\n"
      f"It will watch {plural_noun2} and count how many times they {verb3}.\n"
      f"I don't think it will {verb4} the world or anything, but I'm {adjective5} about it!")

# continuous with commas
print(f"I have a(n) {adjective1} idea for a program!",
      f"It will watch {plural_noun2} and count how many times they {verb3}", 
      f"I don't think it will {verb4} the world or anything, but I'm {adjective5} about it!")

# continuous rewrapped, no commas
print(f"I have a(n) {adjective1} idea for a program! It will watch "
      f"{plural_noun2} and count how many times they {verb3}. I don't think it "
      f"will {verb4} the world or anything, but I'm {adjective5} about it!")

print statements will automatically concatenate strings if listed without using commas. If a comma is used then a space is added between items. I often used the "continuous rewrapped without commas version for lines too long for the line length limit.

Liam White
Liam White
1,969 Points

Thank you for clearing this up for me