Answers for "dice game python"

1

dice rolling simulator python

from random import randint

def roll_dice():
    print(f"Number is: {randint(1,6)}")

# Do this to simulate once
roll_dice()   

# Do this to simulate multiple times
whatever = 12 # Put the number of times you want to simulate here
for number in range(whatever):
    roll_dice()
Posted by: Guest on July-11-2020
0

how to make a dice in python

#For one time roll
from random import randint

dice_roll = randint(1,6) 
#You can change numbers to anything you want, it can go up to 1 million if you really want it to
print("You Threw a", dice_roll)
#That's for one time throw but if you want it for multiple people then do this

#For multiple roles 
import time
from random import randint
for j in range(10):
    dice_roll = randint(1,6)
    time.sleep(3)
    print("You threw a", dice_roll)
Posted by: Guest on October-25-2020
0

how to make a dice program in python

import random
run = 1
level = 0
while(run == 1):
        print("**ROUND " + str(level) + "**") 
        print("player 1: ",random.randint(0, 6))
        print("player 2: ",random.randint(0, 6))
        run = int(input("enter 1 to go again or 0 to end: "))
        print("")
        level += 1
Posted by: Guest on September-07-2020
0

2 plater die game in python

import random

def get_name(key):
    n = ""
    while not n:
        n = input(f"Input your name, {key}: ")
    return n

def throw_dice(key):
    dices = random.choices(range(1,7),k=2)
    print(f"{names[key]} threw: {dices}", end = " ")
    if sum(dices) % 2 == 0:
        score[key] += 10
        print("Even. You earn 10 points.")
    else:
        score[key] -= 5
        print("Odd. You loose 5 points")

def print_score():
    for n in score:
        print(f"  {names[n]} has got {score[n]} points.")

def win_message(s,n):
    print_score()
    if score["P1"] > score["P2"]:
        print(f"{names['P1']} won")
    else:
        print(f"{names['P2']} won") 



player = ""
score = {}
names = {}

for n in ["P1","P2"]:
    names[n] = get_name(n)
    score[n] = 0

# twice the amount of rows wanted, because players take turn

for c in range(10):
    # switches between player1 and player2
    player = "P1" if player != "P1" else "P2"

    print(f"Round {c//2 + 1}: it is {names[player]}'s turn.")
    print_score()
    throw_dice(player)

win_message(score,names)
Posted by: Guest on July-26-2020
0

rolling dice game python code

# Needed to create random numbers to simulate dice roll
import random

# Initialise player scores to 0
player1_score = 0
player2_score = 0

# Repeat everything in this block 10 times
for i in range(10):

    # Generate random numbers between 1 and 6 for each player.
    player1_value = random.randint(1, 6)
    player2_value = random.randint(1, 6)

    # Display the values
    print("Player 1 rolled: ", player1_value)
    print("Player 2 rolled: ", player2_value)

    # Selection: based on comparison of the values, take the appropriate path through the code.
    if player1_value > player2_value:
        print("player 1 wins.")
        player1_score = player1_score + 1  # This is how we increment a variable
    elif player2_value > player1_value:
        print("player 2 wins")
        player2_score = player2_score + 1
    else:
        print("It's a draw")

    input("Press enter to continue.")  # Wait for user input to proceed.

print("### Game Over ###")
print("Player 1 score:", player1_score)
print("Player 2 score:", player2_score)
Posted by: Guest on October-25-2021

Python Answers by Framework

Browse Popular Code Answers by Language