Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- This is educational code for a 2 player game that looks at who has the highest dice roll.
- Python 3.6
- """
- import random
- playerOne = input('What is player 1\'s name?') # We take in our players names here
- playerTwo = input('What is player 2\'s name?')
- print('Welcome to the game ' + playerOne + ' and ' + playerTwo) # Greeting message...just because
- counter = 0 # see below
- # We set a variable called counter, which will be used to control our 'while' loop we're about to run
- # if no variable was set, then the code would run without pause as there would be no escape condition to make the
- # while loop false.
- while counter < 10: # here we tell the computer to check and if counter is less than 10 if so, then loop again
- playerOneRoll = random.randint(0, 6)
- playerTwoRoll = random.randint(0, 6)
- round = counter + 1 # because we start the counter at 0 in order for the program to print 1 I add one here
- print('Round: ' + str(round)) # print the round we're on
- print(playerOne + ' rolled: ' + str(playerOneRoll))
- print(playerTwo + ' rolled: ' + str(playerTwoRoll))
- if playerOneRoll > playerTwoRoll:
- print(playerOne + ' Wins!\n')
- elif playerTwoRoll > playerOneRoll:
- print(playerTwo + ' Wins!\n')
- else:
- print('You tied!\n')
- counter += 1 # very important to add 1 to the counter each time. if you didn't have this, then the program would
- # read counter at 0 and would never make it to ten. This adds one each time we go through the loop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement