Breakout Room 16 - Implementing Mad Libs Generator#17
Breakout Room 16 - Implementing Mad Libs Generator#17anselrognlie wants to merge 1 commit intomainfrom
Conversation
| @@ -1 +1,23 @@ | |||
| #Mad Libs Generator Project | |||
| //Loop back to this point once code finishes | |||
There was a problem hiding this comment.
Consider using "#" instead of "/" for writing comments. "/" are used in JavaScript, Python uses "#"
There was a problem hiding this comment.
| //Loop back to this point once code finishes | |
| # Loop back to this point once code finishes |
| //Loop back to this point once code finishes | ||
| loop = 1 | ||
| while (loop < 9): | ||
| // All the questions that the program asks the user |
There was a problem hiding this comment.
| // All the questions that the program asks the user | |
| # All the questions that the program asks the user |
| place = input("Name a place: ") | ||
| adjective = input("Choose an adjective (Describing word): ") | ||
| third_noun = input("Choose a noun: ") | ||
| // Displays the story based on the users input |
There was a problem hiding this comment.
| // Displays the story based on the users input | |
| # Displays the story based on the users input |
| print ("You may think that is this the",third_noun,",") | ||
| print ("Well it is.") | ||
| print ("------------------------------------------") | ||
| // Loop back to "loop = 1" |
There was a problem hiding this comment.
| // Loop back to "loop = 1" | |
| # Loop back to "loop = 1" |
| #Mad Libs Generator Project | ||
| //Loop back to this point once code finishes | ||
| loop = 1 | ||
| while (loop < 9): |
There was a problem hiding this comment.
A while loop works, however, when we have a fixed number of iterations it is better to use a for loop. In this case, a loop variable is not needed
for _ in range(10)
(https://www.geeksforgeeks.org/difference-between-for-loop-and-while-loop-in-python/)
| noun = input("Choose a noun: ") | ||
| plural_noun = input("Choose a plural noun: ") | ||
| second_noun = input("Choose a noun: ") | ||
| place = input("Name a place: ") |
There was a problem hiding this comment.
For consistency, consider change "Name" for "Choose" as it is implemented on the other input messages.
| // Displays the story based on the users input | ||
| print ("------------------------------------------") | ||
| print ("Be kind to your",noun,"- footed", plural_noun) | ||
| print ("For a duck may be somebody's", seond_noun,",") |
There was a problem hiding this comment.
Fix variable name to "second_noun" instead of "seond_noun", otherwise, it is going to cause a NameError
| print ("------------------------------------------") | ||
| print ("Be kind to your",noun,"- footed", plural_noun) | ||
| print ("For a duck may be somebody's", seond_noun,",") | ||
| print ("Be kind to your",plural_noun,"in",place) | ||
| print ("Where the weather is always",adjective,".") | ||
| print () | ||
| print ("You may think that is this the",third_noun,",") | ||
| print ("Well it is.") |
There was a problem hiding this comment.
For readability, consider using f-strings or string interpolation
print (f"Be kind to your {plural_noun} in {place}")
linakl19
left a comment
There was a problem hiding this comment.
The implementation works, and the requirements are met.
Here are a few general suggestions for improvement:
- Replace // with # for writing comments in Python.
- Instead of using a while loop, consider using a for loop with range(). You can refer to the single-line comments in the code for an example.
- For better readability in print statements, use f-strings instead of comma-separated values.
- To make the code more reusable, consider wrapping it in a function, such as create_story() (This is not necessary but is something good to consider)
Nice work so far. Looking forward to seeing how you refine it! Let me know if you have any questions!
No description provided.