From 7119c73886c943b02b05aaf8f4fd6a56db91d66a Mon Sep 17 00:00:00 2001 From: FJORWB <88600252+fjorwb@users.noreply.github.com> Date: Wed, 2 Nov 2022 18:46:06 -0500 Subject: [PATCH 1/6] fixed py file --- magic8.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/magic8.py b/magic8.py index c02c7c2..f251695 100644 --- a/magic8.py +++ b/magic8.py @@ -1,3 +1,5 @@ +import random + name = "Joe" question = "Will I win the lottery?" answer = "" From 38d4a2d10320007648660f92e067002cc52f211b Mon Sep 17 00:00:00 2001 From: FJORWB <88600252+fjorwb@users.noreply.github.com> Date: Wed, 2 Nov 2022 18:50:32 -0500 Subject: [PATCH 2/6] file py --- magic8.py | 1 - 1 file changed, 1 deletion(-) diff --git a/magic8.py b/magic8.py index f251695..cadcd19 100644 --- a/magic8.py +++ b/magic8.py @@ -1,5 +1,4 @@ import random - name = "Joe" question = "Will I win the lottery?" answer = "" From 94167ccecab2730cfd2a39e7544750b06a0a5588 Mon Sep 17 00:00:00 2001 From: FJORWB <88600252+fjorwb@users.noreply.github.com> Date: Wed, 2 Nov 2022 18:53:09 -0500 Subject: [PATCH 3/6] Fixed py file --- magic8.py | 1 + 1 file changed, 1 insertion(+) diff --git a/magic8.py b/magic8.py index cadcd19..f251695 100644 --- a/magic8.py +++ b/magic8.py @@ -1,4 +1,5 @@ import random + name = "Joe" question = "Will I win the lottery?" answer = "" From e3f142b776c203323f563b24650f0e7d8401ffa9 Mon Sep 17 00:00:00 2001 From: FJORWB <88600252+fjorwb@users.noreply.github.com> Date: Wed, 2 Nov 2022 19:03:36 -0500 Subject: [PATCH 4/6] Fixed py file --- magic8.py | 1 - 1 file changed, 1 deletion(-) diff --git a/magic8.py b/magic8.py index f251695..cadcd19 100644 --- a/magic8.py +++ b/magic8.py @@ -1,5 +1,4 @@ import random - name = "Joe" question = "Will I win the lottery?" answer = "" From 67c70631946c992a1266193a3ffde1f72d6b4287 Mon Sep 17 00:00:00 2001 From: FJORWB <88600252+fjorwb@users.noreply.github.com> Date: Sat, 9 Nov 2024 10:50:48 -0500 Subject: [PATCH 5/6] Fix magic8.py error Related to #3 --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/fjorwb/try-github-CLI-off-platform-project/issues/3?shareId=XXXX-XXXX-XXXX-XXXX). --- magic8.py | 62 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/magic8.py b/magic8.py index cadcd19..30d808f 100644 --- a/magic8.py +++ b/magic8.py @@ -1,31 +1,43 @@ import random +import logging + +logging.basicConfig(level=logging.ERROR, format='%(asctime)s - %(levelname)s - %(message)s') + name = "Joe" question = "Will I win the lottery?" answer = "" -random_number = random.randint(1, 9) -# print(random_number) - -if random_number == 1: - answer = "Yes - definitely" -elif random_number == 2: - answer = "It is decidedly so" -elif random_number == 3: - answer = "Without a doubt" -elif random_number == 4: - answer = "Reply hazy, try again" -elif random_number == 5: - answer = "Ask again later" -elif random_number == 6: - answer = "Better not tell you now" -elif random_number == 7: - answer = "My sources say no" -elif random_number == 8: - answer = "Outlook not so good" -elif random_number == 9: - answer = "Very doubtful" +if not question: + print("Please ask a question.") else: - answer = "Error" - -print(name + " asks: " + question) -print("Magic 8 Ball's answer: " + answer) + try: + random_number = random.randint(1, 9) + assert 1 <= random_number <= 9, "Random number out of range: {}".format(random_number) + except Exception as e: + logging.error("An error occurred: %s", str(e)) + print("An error occurred. Please try again.") + else: + if random_number == 1: + answer = "Yes - definitely" + elif random_number == 2: + answer = "It is decidedly so" + elif random_number == 3: + answer = "Without a doubt" + elif random_number == 4: + answer = "Reply hazy, try again" + elif random_number == 5: + answer = "Ask again later" + elif random_number == 6: + answer = "Better not tell you now" + elif random_number == 7: + answer = "My sources say no" + elif random_number == 8: + answer = "Outlook not so good" + elif random_number == 9: + answer = "Very doubtful" + + if not name: + print("Magic 8 Ball's answer: " + answer) + else: + print(name + " asks: " + question) + print("Magic 8 Ball's answer: " + answer) From 1e1d11f7f8281484e057bbff546f96033a980517 Mon Sep 17 00:00:00 2001 From: FJORWB <88600252+fjorwb@users.noreply.github.com> Date: Sat, 9 Nov 2024 17:13:10 +0000 Subject: [PATCH 6/6] input for question added --- magic8.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/magic8.py b/magic8.py index 30d808f..e66d450 100644 --- a/magic8.py +++ b/magic8.py @@ -4,9 +4,11 @@ logging.basicConfig(level=logging.ERROR, format='%(asctime)s - %(levelname)s - %(message)s') name = "Joe" -question = "Will I win the lottery?" +question = "" answer = "" +question = input("Ask a question: ") + if not question: print("Please ask a question.") else: