Magic 8 ball code











up vote
1
down vote

favorite












This code is for a magic 8 ball in Python. What do you think?



import random
import time
choices=[
"Definitely",
"Yes",
"Probably",
"Mabye",
"Probably Not",
"No",
"Definitely Not",
"I don't know",
"Ask Later",
"I'm too tired"
]
while True:
input("Ask the mighty 8-Ball a questionnOo")
for i in range(0,3):
print("Shaking...")
time.sleep(1)
print(random.choice(choices))









share|improve this question




























    up vote
    1
    down vote

    favorite












    This code is for a magic 8 ball in Python. What do you think?



    import random
    import time
    choices=[
    "Definitely",
    "Yes",
    "Probably",
    "Mabye",
    "Probably Not",
    "No",
    "Definitely Not",
    "I don't know",
    "Ask Later",
    "I'm too tired"
    ]
    while True:
    input("Ask the mighty 8-Ball a questionnOo")
    for i in range(0,3):
    print("Shaking...")
    time.sleep(1)
    print(random.choice(choices))









    share|improve this question


























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      This code is for a magic 8 ball in Python. What do you think?



      import random
      import time
      choices=[
      "Definitely",
      "Yes",
      "Probably",
      "Mabye",
      "Probably Not",
      "No",
      "Definitely Not",
      "I don't know",
      "Ask Later",
      "I'm too tired"
      ]
      while True:
      input("Ask the mighty 8-Ball a questionnOo")
      for i in range(0,3):
      print("Shaking...")
      time.sleep(1)
      print(random.choice(choices))









      share|improve this question















      This code is for a magic 8 ball in Python. What do you think?



      import random
      import time
      choices=[
      "Definitely",
      "Yes",
      "Probably",
      "Mabye",
      "Probably Not",
      "No",
      "Definitely Not",
      "I don't know",
      "Ask Later",
      "I'm too tired"
      ]
      while True:
      input("Ask the mighty 8-Ball a questionnOo")
      for i in range(0,3):
      print("Shaking...")
      time.sleep(1)
      print(random.choice(choices))






      python






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 28 '16 at 21:06









      Mast

      7,43863685




      7,43863685










      asked Jan 28 '16 at 20:57







      user95800





























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          7
          down vote



          accepted










          Let's go instruction by instruction.



          Imports



          They are fine. However, with such a few features used from each module, you could explicitly state them so the reader know what to expect:



          from random import choice
          from time import sleep


          Constants



          A little problem on naming here. choices is not meaningful in the context as there is nothing to choose from (for a user perspective). Answers or possibilities seems a better fit to me. You might want to use uppercase variable name as it denotes a constant value.



          And, since you do not plan on modifying its value during execution, you could enforce that using a tuple instead of a list:



          ANSWERS = (
          "Definitely",
          "Yes",
          "Probably",
          "Mabye",
          "Probably Not",
          "No",
          "Definitely Not",
          "I don't know",
          "Ask Later",
          "I'm too tired",
          )


          Also note the spacing around = and the indentation to improve readability.



          Loops



          Infinite loops are great. They are so great, no one ever stopped using one.



          Joking aside, the only way for you users to exit your program is by using ctrl-c. You may want to provide a cleaner way; for instance if they input an empty line:



          while input(...):
          #do stuff


          Inputs



          The 'Oo' part on the second line of the input feels weird. Try to come up with a more conventionnal prompt delimiter.



          Also remember that the text entered by the user will be right after the printed string: add a space for ease of use.



          input("Ask the mighty 8-Ball a questionn> ")


          Iterations



          range(0, x) is better written as range(x). It has the exact same meaning but reads better.



          By convention, variables of a for loop that are unused in their body are named _:



          for _ in range(3):


          Prints



          You could have a fancier output and use that i variable if your output uses variable number of dot:



          print("Shaking{}".format("."*i))


          Sleeps



          One full second between shakings, meaning 3 seconds before an answer seems pretty long for this kind of program. I would reduce that time a bit to 0.6 or 0.7 seconds:



          sleep(.7) # remember the imports


          Lastly



          Nothing more to say for the last line. But don't forget to adapt it to the previous changes:



          print(choice(ANSWERS))





          share|improve this answer





















          • I think that ANSWERS is more appropriate as a list than as a tuple, conceptually. It is more akin to rows in a one-column database table than to one row with many columns.
            – 200_success
            Jan 29 '16 at 4:00


















          up vote
          2
          down vote













          Since i isn't being used, consider replacing it with _ to indicate that it's not being used.






          share|improve this answer




















            protected by Vogel612 Nov 16 at 9:43



            Thank you for your interest in this question.
            Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



            Would you like to answer one of these unanswered questions instead?













            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            7
            down vote



            accepted










            Let's go instruction by instruction.



            Imports



            They are fine. However, with such a few features used from each module, you could explicitly state them so the reader know what to expect:



            from random import choice
            from time import sleep


            Constants



            A little problem on naming here. choices is not meaningful in the context as there is nothing to choose from (for a user perspective). Answers or possibilities seems a better fit to me. You might want to use uppercase variable name as it denotes a constant value.



            And, since you do not plan on modifying its value during execution, you could enforce that using a tuple instead of a list:



            ANSWERS = (
            "Definitely",
            "Yes",
            "Probably",
            "Mabye",
            "Probably Not",
            "No",
            "Definitely Not",
            "I don't know",
            "Ask Later",
            "I'm too tired",
            )


            Also note the spacing around = and the indentation to improve readability.



            Loops



            Infinite loops are great. They are so great, no one ever stopped using one.



            Joking aside, the only way for you users to exit your program is by using ctrl-c. You may want to provide a cleaner way; for instance if they input an empty line:



            while input(...):
            #do stuff


            Inputs



            The 'Oo' part on the second line of the input feels weird. Try to come up with a more conventionnal prompt delimiter.



            Also remember that the text entered by the user will be right after the printed string: add a space for ease of use.



            input("Ask the mighty 8-Ball a questionn> ")


            Iterations



            range(0, x) is better written as range(x). It has the exact same meaning but reads better.



            By convention, variables of a for loop that are unused in their body are named _:



            for _ in range(3):


            Prints



            You could have a fancier output and use that i variable if your output uses variable number of dot:



            print("Shaking{}".format("."*i))


            Sleeps



            One full second between shakings, meaning 3 seconds before an answer seems pretty long for this kind of program. I would reduce that time a bit to 0.6 or 0.7 seconds:



            sleep(.7) # remember the imports


            Lastly



            Nothing more to say for the last line. But don't forget to adapt it to the previous changes:



            print(choice(ANSWERS))





            share|improve this answer





















            • I think that ANSWERS is more appropriate as a list than as a tuple, conceptually. It is more akin to rows in a one-column database table than to one row with many columns.
              – 200_success
              Jan 29 '16 at 4:00















            up vote
            7
            down vote



            accepted










            Let's go instruction by instruction.



            Imports



            They are fine. However, with such a few features used from each module, you could explicitly state them so the reader know what to expect:



            from random import choice
            from time import sleep


            Constants



            A little problem on naming here. choices is not meaningful in the context as there is nothing to choose from (for a user perspective). Answers or possibilities seems a better fit to me. You might want to use uppercase variable name as it denotes a constant value.



            And, since you do not plan on modifying its value during execution, you could enforce that using a tuple instead of a list:



            ANSWERS = (
            "Definitely",
            "Yes",
            "Probably",
            "Mabye",
            "Probably Not",
            "No",
            "Definitely Not",
            "I don't know",
            "Ask Later",
            "I'm too tired",
            )


            Also note the spacing around = and the indentation to improve readability.



            Loops



            Infinite loops are great. They are so great, no one ever stopped using one.



            Joking aside, the only way for you users to exit your program is by using ctrl-c. You may want to provide a cleaner way; for instance if they input an empty line:



            while input(...):
            #do stuff


            Inputs



            The 'Oo' part on the second line of the input feels weird. Try to come up with a more conventionnal prompt delimiter.



            Also remember that the text entered by the user will be right after the printed string: add a space for ease of use.



            input("Ask the mighty 8-Ball a questionn> ")


            Iterations



            range(0, x) is better written as range(x). It has the exact same meaning but reads better.



            By convention, variables of a for loop that are unused in their body are named _:



            for _ in range(3):


            Prints



            You could have a fancier output and use that i variable if your output uses variable number of dot:



            print("Shaking{}".format("."*i))


            Sleeps



            One full second between shakings, meaning 3 seconds before an answer seems pretty long for this kind of program. I would reduce that time a bit to 0.6 or 0.7 seconds:



            sleep(.7) # remember the imports


            Lastly



            Nothing more to say for the last line. But don't forget to adapt it to the previous changes:



            print(choice(ANSWERS))





            share|improve this answer





















            • I think that ANSWERS is more appropriate as a list than as a tuple, conceptually. It is more akin to rows in a one-column database table than to one row with many columns.
              – 200_success
              Jan 29 '16 at 4:00













            up vote
            7
            down vote



            accepted







            up vote
            7
            down vote



            accepted






            Let's go instruction by instruction.



            Imports



            They are fine. However, with such a few features used from each module, you could explicitly state them so the reader know what to expect:



            from random import choice
            from time import sleep


            Constants



            A little problem on naming here. choices is not meaningful in the context as there is nothing to choose from (for a user perspective). Answers or possibilities seems a better fit to me. You might want to use uppercase variable name as it denotes a constant value.



            And, since you do not plan on modifying its value during execution, you could enforce that using a tuple instead of a list:



            ANSWERS = (
            "Definitely",
            "Yes",
            "Probably",
            "Mabye",
            "Probably Not",
            "No",
            "Definitely Not",
            "I don't know",
            "Ask Later",
            "I'm too tired",
            )


            Also note the spacing around = and the indentation to improve readability.



            Loops



            Infinite loops are great. They are so great, no one ever stopped using one.



            Joking aside, the only way for you users to exit your program is by using ctrl-c. You may want to provide a cleaner way; for instance if they input an empty line:



            while input(...):
            #do stuff


            Inputs



            The 'Oo' part on the second line of the input feels weird. Try to come up with a more conventionnal prompt delimiter.



            Also remember that the text entered by the user will be right after the printed string: add a space for ease of use.



            input("Ask the mighty 8-Ball a questionn> ")


            Iterations



            range(0, x) is better written as range(x). It has the exact same meaning but reads better.



            By convention, variables of a for loop that are unused in their body are named _:



            for _ in range(3):


            Prints



            You could have a fancier output and use that i variable if your output uses variable number of dot:



            print("Shaking{}".format("."*i))


            Sleeps



            One full second between shakings, meaning 3 seconds before an answer seems pretty long for this kind of program. I would reduce that time a bit to 0.6 or 0.7 seconds:



            sleep(.7) # remember the imports


            Lastly



            Nothing more to say for the last line. But don't forget to adapt it to the previous changes:



            print(choice(ANSWERS))





            share|improve this answer












            Let's go instruction by instruction.



            Imports



            They are fine. However, with such a few features used from each module, you could explicitly state them so the reader know what to expect:



            from random import choice
            from time import sleep


            Constants



            A little problem on naming here. choices is not meaningful in the context as there is nothing to choose from (for a user perspective). Answers or possibilities seems a better fit to me. You might want to use uppercase variable name as it denotes a constant value.



            And, since you do not plan on modifying its value during execution, you could enforce that using a tuple instead of a list:



            ANSWERS = (
            "Definitely",
            "Yes",
            "Probably",
            "Mabye",
            "Probably Not",
            "No",
            "Definitely Not",
            "I don't know",
            "Ask Later",
            "I'm too tired",
            )


            Also note the spacing around = and the indentation to improve readability.



            Loops



            Infinite loops are great. They are so great, no one ever stopped using one.



            Joking aside, the only way for you users to exit your program is by using ctrl-c. You may want to provide a cleaner way; for instance if they input an empty line:



            while input(...):
            #do stuff


            Inputs



            The 'Oo' part on the second line of the input feels weird. Try to come up with a more conventionnal prompt delimiter.



            Also remember that the text entered by the user will be right after the printed string: add a space for ease of use.



            input("Ask the mighty 8-Ball a questionn> ")


            Iterations



            range(0, x) is better written as range(x). It has the exact same meaning but reads better.



            By convention, variables of a for loop that are unused in their body are named _:



            for _ in range(3):


            Prints



            You could have a fancier output and use that i variable if your output uses variable number of dot:



            print("Shaking{}".format("."*i))


            Sleeps



            One full second between shakings, meaning 3 seconds before an answer seems pretty long for this kind of program. I would reduce that time a bit to 0.6 or 0.7 seconds:



            sleep(.7) # remember the imports


            Lastly



            Nothing more to say for the last line. But don't forget to adapt it to the previous changes:



            print(choice(ANSWERS))






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jan 29 '16 at 0:26









            Mathias Ettinger

            22.7k33077




            22.7k33077












            • I think that ANSWERS is more appropriate as a list than as a tuple, conceptually. It is more akin to rows in a one-column database table than to one row with many columns.
              – 200_success
              Jan 29 '16 at 4:00


















            • I think that ANSWERS is more appropriate as a list than as a tuple, conceptually. It is more akin to rows in a one-column database table than to one row with many columns.
              – 200_success
              Jan 29 '16 at 4:00
















            I think that ANSWERS is more appropriate as a list than as a tuple, conceptually. It is more akin to rows in a one-column database table than to one row with many columns.
            – 200_success
            Jan 29 '16 at 4:00




            I think that ANSWERS is more appropriate as a list than as a tuple, conceptually. It is more akin to rows in a one-column database table than to one row with many columns.
            – 200_success
            Jan 29 '16 at 4:00












            up vote
            2
            down vote













            Since i isn't being used, consider replacing it with _ to indicate that it's not being used.






            share|improve this answer

























              up vote
              2
              down vote













              Since i isn't being used, consider replacing it with _ to indicate that it's not being used.






              share|improve this answer























                up vote
                2
                down vote










                up vote
                2
                down vote









                Since i isn't being used, consider replacing it with _ to indicate that it's not being used.






                share|improve this answer












                Since i isn't being used, consider replacing it with _ to indicate that it's not being used.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 28 '16 at 21:57









                Jared Goguen

                777312




                777312

















                    protected by Vogel612 Nov 16 at 9:43



                    Thank you for your interest in this question.
                    Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



                    Would you like to answer one of these unanswered questions instead?



                    Popular posts from this blog

                    Mont Emei

                    Province de Neuquén

                    Journaliste