Apr 1, 2020 06:21 AM
(This post was last modified: Apr 1, 2020 06:29 AM by ICUP.)
Hi.
Very beginner here. Just finished the basics yesterday and still watching Automate the Boring Stuff with Python.
I'm trying to write my first dice rolling game but I'd like to add more stuff into it since the tut that I followed was very basic.
I'd like it to roll only when the user is ready / presses a key .
1st roll for Player1 only when player 1 presses a key
1st roll for Player 2 only when player 2 presses a key
2nd roll for Player1 only when player 1 presses a key
and so on
loop until they reach round 3 and finds a winner.
I feel like the main function needs to be changed by I don't know how and I'm stuck.
Thank you!
Very beginner here. Just finished the basics yesterday and still watching Automate the Boring Stuff with Python.
I'm trying to write my first dice rolling game but I'd like to add more stuff into it since the tut that I followed was very basic.
I'd like it to roll only when the user is ready / presses a key .
1st roll for Player1 only when player 1 presses a key
1st roll for Player 2 only when player 2 presses a key
2nd roll for Player1 only when player 1 presses a key
and so on
loop until they reach round 3 and finds a winner.
PHP Code
<?php
import random
player1_name = input("Hi, player 1. Insert your name: ")
player2_name = input("Hi, player 2. Insert your name: ")
ready_to_roll = True
print("Hello " + player1_name + " and " + player2_name + "!")
print("Are you ready to roll, " + player1_name + "?")
input("Press enter to continue...")
def main():
player1 = 0
player1wins = 0
player2 = 0
player2wins = 0
rounds = 1
while rounds != 4:
print("Round " + str(rounds))
player1 = dice_roll()
player2 = dice_roll()
print(player1_name + " Roll: " + str(player1))
print(player2_name + " Roll: " + str(player2))
if player1 == player2:
print("Draw!")
elif player1 > player2:
player1wins = player1wins + 1
print(player1_name + " wins!\n")
else:
player2wins = player2wins + 1
print(player2_name + " wins!\n")
rounds = rounds + 1
if player1wins == player2wins:
print("Draw")
elif player1wins > player2wins:
print("Player 1 wins the game.")
else:
print("Player 2 wins the game.")
def dice_roll():
diceRoll = random.randint(1, 6)
return diceRoll
main()
I feel like the main function needs to be changed by I don't know how and I'm stuck.
Thank you!


![[Image: qZ42qWp.jpg]](https://i.imgur.com/qZ42qWp.jpg)

![[Image: 0DvFxnA.gif]](https://i.imgur.com/0DvFxnA.gif)