dice - Very basic python -


An error is occurring but I do not know why .. (I'm learning) my code; Import random inputs ("press enter to roll dice") Global Answer DRP Roll (Degree): Results = Random.RandRange (1,6) Print ("Landed it . "+ Str (Result) Answer = Input (" Would you like to play again? [Y / n] ") rollDice (); If (answer == "Y" or "Y"): rollDice ();

Error; (Some scripts work)

  Enter the dice to roll it to land ..5 Do you want to play again? [Y / n] Y traceback (most recent call final): file "diceRoller.py", line 11, & lt; Module & gt; Name (Answer == "Y" or "Y"): Name: Error: Name 'Answer' is not defined    

At the top of what the answers are saying, I recommend that you do not use global , instead I will write return For example:

  import random input (press "enter to roll the dice") def roll (): result = random Answer: "It has gone wrong again", "it landed on .." + str (result) Answer = input (a) .randrange (1,6) print () in the north ("Y", "Y") "Do you want to play again?" [Y / n] ") RollDice (): Continue   

In addition, a loop instead of a if statement Use Otherwise you will not be able to ask the user whether he wants to continue indefinitely.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -