diff --git a/Madlibs b/Madlibs new file mode 100644 index 0000000..1d73696 --- /dev/null +++ b/Madlibs @@ -0,0 +1,61 @@ +# Mad Libs Game in Python + +import random + +def get_words(prompts): + words = {} + for key, text in prompts.items(): + user_input = input(f"Enter {text}: ") + words[key] = user_input.strip() + return words + + +def play_round(): + # Define the blanks needed + prompts = { + "name": "a name", + "place": "a place", + "adjective1": "an adjective", + "adjective2": "another adjective", + "noun1": "a noun", + "noun2": "another noun", + "verb_past": "a verb (past tense)", + "verb_ing": "a verb ending with -ing", + "animal": "an animal", + "number": "a number" + } + + words = get_words(prompts) + + # Story templates + stories = [ + ( + f"One day, {words['name']} went to {words['place']} with a very {words['adjective1']} {words['animal']}. " + f"Suddenly, a {words['adjective2']} {words['noun1']} {words['verb_past']} past them while {words['verb_ing']}. " + f"Everyone dropped {words['number']} {words['noun2']} and ran away!" + ), + ( + f"At {words['place']}, {words['name']} found a {words['adjective1']} {words['noun1']}. " + f"They {words['verb_past']} it and started {words['verb_ing']}. " + f"A {words['adjective2']} {words['animal']} appeared and gave them {words['number']} {words['noun2']} as a reward." + ), + ] + + print("\n--- Your Mad Libs Story ---\n") + print(random.choice(stories)) + print("\n---------------------------\n") + + +def main(): + print("🎉 Welcome to the Mad Libs Game! 🎉") + + while True: + play_round() + again = input("Play again? (y/n): ").lower().strip() + if again != 'y': + print("Thanks for playing! 👋") + break + + +if __name__ == "__main__": + main()