Question

In: Computer Science

In Python write a function that simulates the throwing of any even numbered dice which will...

In Python write a function that simulates the throwing of any even numbered dice which will be passed on as a parameter: customDice(sides). The function will return a random number rolled for that particular type of dice. Write the program that will utilize the customDice function with the following specification: Ask the user to pick which even-sided dice to use. The program will then roll the dice twice. If the total of both rolls is greater than the number of die sides+1, then they lose. If not, they win. Write statements that prompt the user for the type of dice to use, print the value from the two rolls and a message whether they win or lose. If the user enters an odd number, ask for the input again.

Sample dialogs:

Please choose an even-sided dice: 3

Sorry, it must be an even-sided dice.

Please choose an even-sided dice: 10

Roll 1: 3

Roll 2: 10

Total: 13

You lose (13 > 11)!

Please choose an even-sided dice: 8

Roll 1: 3

Roll 2: 2

Total: 5

You win (5 < 9)!

Solutions

Expert Solution

i hope u will understand the program .. i have commented every statement using '#' for easy understanding..

comment if u have any query...:)

import random
def customdice(side):       #we defined customedice function
    roll1 = random.randint(1,6)  #roll1 stores random numnber generated by dice
    roll2 = random.randint(1,6)  #roll2 stores random numnber generated by dice
    print("Roll 1:",roll1)
    print("Roll 2:",roll2)
    sum = roll1 + roll2   
    return  sum     #it will return total of dices to calling function

def even(side): #checking for user entered even number or not
    if side%2==0 :
        return side
    else:
        print("Sorry,it must be an even sided dice")
        return

ch= 'y' 
while ch == 'y':   #it will continue until user don't want 
    side = int(input("Please choose an even sided dice")) #user input for dice
    if side == even(side) :   #calling even Function
        sum = customdice(side)
        print("Total :",sum)
        if sum > side+1 :    #checking winning strategies
            print("You Lose.(",sum,">",side+1,")!")
        elif sum == side+1 :
            print("Tied try again.(", sum, "=", side+1, ")!")
        else :
            print("You Won.(", sum, "<", side+1,")!")
    ch = input("Enter 'y' to continue or 'n' to Exit") #asking user to continue or not

output :


Related Solutions

Write a python program that simulates a simple dice gambling game. The game is played as...
Write a python program that simulates a simple dice gambling game. The game is played as follows: Roll a six sided die. If you roll a 1, 2 or a 3, the game is over. If you roll a 4, 5, or 6, you win that many dollars ($4, $5, or $6), and then roll again. With each additional roll, you have the chance to win more money, or you might roll a game-ending 1, 2, or 3, at which...
Prepare a class and tester that simulates and tabulates the result of repeatedly throwing two dice.  Recall...
Prepare a class and tester that simulates and tabulates the result of repeatedly throwing two dice.  Recall a dice, a six-sided cube with 1 through 6 dots on each side. Using a now familiar looping user experience, the user enters the number of throws. Then, the system simulates the throws and displays the results using a frequency distribution chart. For instance: Please, use this statement to get the dice action started! String[] labels = {"Snake Eyes", "Ace Deuce", "Hard Four", "Fever...
In python please write the following code the problem. Write a function called play_round that simulates...
In python please write the following code the problem. Write a function called play_round that simulates two people drawing cards and comparing their values. High card wins. In the case of a tie, draw more cards. Repeat until someone wins the round. The function has two parameters: the name of player 1 and the name of player 2. It returns a string with format '<winning player name> wins!'. For instance, if the winning player is named Rocket, return 'Rocket wins!'.
Python language: Write a function dice(n) that returns a list with the results of n dice...
Python language: Write a function dice(n) that returns a list with the results of n dice rolls conducted with a six sided dice. Use Numpy's random number functions to do this (Hint: use randint() within numpy's random module). i.e. dice(3) returns something like [2,3,5] to indicate the first dice obtained a 2, the second a 3 etc
. Dice rolling: In c++Write a program that simulates the rolling of two dice. The sum...
. Dice rolling: In c++Write a program that simulates the rolling of two dice. The sum of the two values should then be calculated. [Note: Each die can show an integer value from 1 to 6, so the sum of the two values will vary from 2 to 12, with 7 being the most frequent sum and 2 and 12 being the least frequent sums.] The following table shows the 36 possible combinations of the two dice. Your program should...
Write a Python function which finds the smallest even and odd numbers in a given list....
Write a Python function which finds the smallest even and odd numbers in a given list. (Use for loop and if conditions for this problem)
1. Write a program which simulates rolling dice. It should: Display the random number rolled Ask...
1. Write a program which simulates rolling dice. It should: Display the random number rolled Ask the user if they want to roll again. If they don't want to roll again, the program should end. If they do want to roll again, the new number should display. At a minimum, the die should have 6 sides, but if you want to use a d12 or d20, that is fine too. USE PYTHON
Write a program in C++ called RollDice.cpp that simulates rolling a pair of dice until the...
Write a program in C++ called RollDice.cpp that simulates rolling a pair of dice until the total on the dice comes up to be a given number. Ask the user for the number that you are rolling for. To have your program roll two dice, use the rand() function this way: die1 = rand() % 6 + 1; die2 = rand() % 6 + 1; Your program then computes and prints the number of rolls it takes to get the...
USE PYTHON : # Problem Set 04: - Write a function to seek for all even...
USE PYTHON : # Problem Set 04: - Write a function to seek for all even numbers and odd numbers in the middle of two number A and B. Print even and odd numbers in 1 and 2020 (including both these two numbers) # Problem Set 05: - A website requests an user to input his account password. - Write a program to examize the validity of the password. - The valid password must consists of: - At least 1...
Write a Matlab function called “SimpleChannel” which takes a signal as an input, simulates a channel...
Write a Matlab function called “SimpleChannel” which takes a signal as an input, simulates a channel and returns the transmitted signal.. SimpleChannel function will add a randomly generated noise (look for “rand” function) to the signal and return it. You can adjust the amplitude of the noise as you want in order to have a distinct noise effect. Then write another matlab code to show the channel noise. First create the signal and then simulate the channel by using your...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT