diff --git a/8balls-magic.py b/8balls-magic.py index 956c2cc..2acf8ee 100644 --- a/8balls-magic.py +++ b/8balls-magic.py @@ -1,37 +1,25 @@ # Import the modules import sys +import os +from os import system import random #how to improve such if else logic with contineous QA? -ans = True - -while ans: - question = raw_input("Ask the magic 8 ball a question: (press enter to quit) ") - - answers = random.randint(1,8) - +#Answer = You Can add while True statement +# You doesnot need to create a boolean for this one +answers = random.randint(1,8) # Here I have put this not in while loop because it will generate a random number everytime. +# print(answers) +while True: + question = int(input("Ask the magic 8 ball a question: (Enter to quit) ")) if question == "": sys.exit() - - elif answers == 1: - print "It is certain" - - elif answers == 2: - print "Outlook good" - - elif answers == 3: - print "You may rely on it" - - elif answers == 4: - print "Ask again later" - - elif answers == 5: - print "Concentrate and ask again" - - elif answers == 6: - print "Reply hazy, try again" - - elif answers == 7: - print "My reply is no" - - elif answers == 8: - print "My sources say no" + elif question == "shutdown": + os.system("-s shutdown") + # Here I have put question bcoz the number that the user enters will be put in the variable(question). You can do better. + elif answers == question: + print("Nice, you r correct") + answers = random.randint(1,8) + # print(answers) + # Always Remember to typecast the numbers in int not in string........I have worked in your project. Plz save it.Thanks + # From India + else: + print("you are incorrect")