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...
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!'.
. 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...
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
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...
PYTHON BEGINNER Problem Write a program which, given a number, simulates rolling a pair of six-sided...
PYTHON BEGINNER Problem Write a program which, given a number, simulates rolling a pair of six-sided dice that number of times. The program should keep track of how many times each possible sum comes up using a list. The list's first element should contain how many times a total of 2 was rolled, the second should contain how many times a total of 3 was rolled, and so on all the way through to 12. When all rolls are complete,...
Write a python function that will return the total length of line that passes through any...
Write a python function that will return the total length of line that passes through any number of provided points ( (x,y) ). The points should be passed as individual tuples or lists. The function should also have a parameter (True or False) to indicate whether the line should start from the origin, and that parameter should default to False. If True, the returned value should include the distance from the origin to the first point, otherwise start adding distances...
You will write a program using Python that simulates an Automatic Teller Machine (ATM). For this...
You will write a program using Python that simulates an Automatic Teller Machine (ATM). For this program, your code can have user defined functions (but not required), the program must not call on any external functions or modules to handle any of the input, computational, and output requirements. Requirements: There is a customer with the following credential and can only access the system if the Access Code is correct: • Name: Peter Parker, Access Code: 2222 • When the program...
Write a Python function ???????? that takes in a nonnegative semiprime number ? which is the...
Write a Python function ???????? that takes in a nonnegative semiprime number ? which is the product of two prime numbers ? and ? and returns the tuple ( ?, ? ) where ?≤? . Example: ????????(22)=(2,11) Example: ????????(3605282209)=(59447,60647) This problem has a time-out limit of 1 second and a memory limit of 1MB. The number ? in all test-cases will satisfy 4≤?≤800000000000000 For example: Test Result print(factorMe(22)) (2, 11) print(factorMe(3605282209)) (59447, 60647)
Write a Python program which uses a function to calculate the perimeter of a rectangle. a...
Write a Python program which uses a function to calculate the perimeter of a rectangle. a function named volume to calculate the volume of a cylinder volume = 3.14 x radius x radius x height .b function named volume to calculate the volume of a cuboid volume = Length x width x ht Write a Python Program to calculate the sum of all odd numbers for 2 to 20 using a for loop. 4. Write statements that assign random integers...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT