From adf919f22a9d526302ddacb04994836065e1ab01 Mon Sep 17 00:00:00 2001 From: Aravinthan Date: Sat, 5 Jul 2025 00:06:56 +0530 Subject: [PATCH] Update 29_fortune_cookie_2.py --- 6-functions/29_fortune_cookie_2.py | 56 ++++++++++-------------------- 1 file changed, 18 insertions(+), 38 deletions(-) diff --git a/6-functions/29_fortune_cookie_2.py b/6-functions/29_fortune_cookie_2.py index 510b43b..50f056f 100644 --- a/6-functions/29_fortune_cookie_2.py +++ b/6-functions/29_fortune_cookie_2.py @@ -2,45 +2,25 @@ # Codédex import random - -options = [ - 'Don’t pursue happiness – create it.', - 'All things are difficult before they are easy.', - 'The early bird gets the worm, but the second mouse gets the cheese.', - 'If you eat something and nobody sees you eat it, it has no calories.', - 'Someone in your life needs a letter from you.', - 'Don’t just think. Act!', - 'Your heart will skip a beat.', - 'The fortune you search for is in another cookie.', - 'Help! I’m being held prisoner in a Chinese bakery!' -] - def fortune(): - random_fortune = random.randint(0, len(options) - 1) - - if random_fortune == 0: - option = options[0] - elif random_fortune == 1: - option = options[1] - elif random_fortune == 2: - option = options[2] - elif random_fortune == 3: - option = options[3] - elif random_fortune == 4: - option = options[4] - elif random_fortune == 5: - option = options[5] - elif random_fortune == 6: - option = options[6] - elif random_fortune == 7: - option = options[7] - elif random_fortune == 8: - option = options[8] + random_fortune = random.randint(0,7) + if random_fortune==0: + print("Don't pursue happiness – create it.") + elif random_fortune==1: + print("All things are difficult before they are easy.") + elif random_fortune==2: + print("The early bird gets the worm, but the second mouse gets the cheese.") + elif random_fortune==3: + print("Someone in your life needs a letter from you.") + elif random_fortune==4: + print("Don't just think. Act!") + elif random_fortune==5: + print("Your heart will skip a beat.") + elif random_fortune==6: + print("The fortune you search for is in another cookie.") else: - option = 'Error' + print("Help! I'm being held prisoner in a Chinese bakery!") +fortune() - print(option) -fortune() -fortune() -fortune() +