Search the Community
Showing results for tags 'python_online'.
Found 1 result
Few programs start with all of their features, so the first version will only implement the basics. First a couple of definitions: A variable is a value that is subject to change, and they are used a lot in Python. Whenever you need your program to "remember" something, you use a variable. In fact, almost all the information that code works with is stored in variables. For example, in the math equation x + 5 = 20, the variable is x, because the letter x is a placeholder for a value. An integer is a number; it can be positive or negative. For example, 1 and -1 are both integers. So are 14, 21, and even 10,947. Variables in Python are easy to create and easy to work with. This initial version of the dice game uses two variables: player and ai. Type the following code into a new text file called dice_alpha.py: import random player = random.randint(1,6) ai = random.randint(1,6) if player > ai : print("You win") # notice indentation else: print("You lose") Launch your game to make sure it works. This basic version of your dice game works pretty well. It accomplishes the basic goals of the game, but it doesn't feel much like a game. The player never knows what they rolled or what the computer rolled, and the game ends even if the player would like to play again. This is common in the first version of software (called an alpha version). Now that you are confident that you can accomplish the main part (rolling a die), it's time to add to the program.