Question

In: Computer Science

Python: Accumulator pattern and conditionals. Write a function play that takes integers rounds and sides and...

Python: Accumulator pattern and conditionals.

Write a function play that takes integers rounds and sides and does the following

 Plays round number of rounds, rolling two s-sided dice per round (use roll).

 Uses the previous functions to calculate the score of each round  Prints out the dice rolls and the score for each round

 Accumulates the score over all rounds

 Returns the final score over all rounds.

*Write a function result that takes an arguments goal and score and

 Prints the score. Then it prints one of the following:

o If the score at least twice the goal then the function should print “Nailed it!”

o If the score is at least the goal print “So so performance”

o Otherwise print “Not good… not good at all!”

Solutions

Expert Solution

import random                         #   to generate random value
score = 0
def scoreCalc(dc1, dc2):
    total_round_wise = dc1 +dc2         #  round score
    global score
    score += dc1+dc2                    #  aggregate score calculate
    return total_round_wise             #   return round score
    
def play(rounds, sides):
    i=0
    while(i != rounds):
        ch = input("Press any key to roll the two dices.\n")
        dice1 = random.randint(1,sides)            #   random number for dice 1
        print("First dice: {}".format(dice1))
        dice2 = random.randint(1,sides)             #   random number for dice 2
        print("Second dice: {}".format(dice2))
        print("Your score of round {} is: {}".format(i+1, scoreCalc(dice1, dice2)))   #   round score print
        i += 1          #   next round

def result(goal, final_score):
    if(final_score >= int(2*goal)):
        print("\nNailed it!")
    elif(final_score >= goal and final_score < int(2*goal)):
        print("\nSo so performance")
    else:
        print("Not good… not good at all!")
    
r = int(input("Input number of round: "))
s = int(input("Input number of sides of dice: "))
play(r, s)                           #   calling play function
goal = int(input("Input your Goal: "))
print("Your total score is: {}".format(score))
result(goal, score)      #   call result function
    

OUTPUT:


Related Solutions

Write a Python function that takes a list of integers as a parameter and returns the...
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
Write a Python function that takes a list of integers as a parameter and returns the...
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
USING PYTHON, write a function that takes a list of integers as input and returns a...
USING PYTHON, write a function that takes a list of integers as input and returns a list with only the even numbers in descending order (Largest to smallest) Example: Input list: [1,6,3,8,2,5] List returned: [8, 6, 2]. DO NOT use any special or built in functions like append, reverse etc.
Python : Write the function inAWhile that takes two integers t and d, where t is...
Python : Write the function inAWhile that takes two integers t and d, where t is the present time on a 12-hour clock, rounded to an integer (so t is an integer in the interval [1,12]) and d is an integer increment in hours, and returns the time on a 12-hour clock in d hours. For example, in 2 hours from 3 o’clock, it will be 5 o’clock, so inAWhile (3, 2) = 5. Notice that 12 is followed by...
Python: Write the function pixelLuminance that takes 3 integers r, g, and b, each between 0...
Python: Write the function pixelLuminance that takes 3 integers r, g, and b, each between 0 and 255 (inclusive), representing the red, green, and blue intensity of a pixel and returns the luminance of this pixel as an integer. The function expects each parameter r, g, and b to be an integer in the interval [0,255]. You should use assertions to enforce this constraint.
Write a Scheme function that takes a list of integers and returns all odd integers on...
Write a Scheme function that takes a list of integers and returns all odd integers on the list in the original order: (odd-numbers `(2 4 9 16 25 7)) (9 25 7) Hint: 2 (remainder 13 5) 3 Please explain every step
Write a function that takes a list of integers as input and returns a list with...
Write a function that takes a list of integers as input and returns a list with only the even numbers in descending order (Largest to smallest) Example: Input list: [1,6,3,8,2,5] List returned: [8, 6, 2] Do not use any special or built in functions like append, reverse etc.
Python: Write a function that receives a one dimensional array of integers and returns a Python...
Python: Write a function that receives a one dimensional array of integers and returns a Python tuple with two values - minimum and maximum values in the input array. You may assume that the input array will contain only integers and will have at least one element. You do not need to check for those conditions. Restrictions: No built-in Python data structures are allowed (lists, dictionaries etc). OK to use a Python tuple to store and return the result. Below...
C++ The minimum function. (a) Write a function that takes two integers and returns the value...
C++ The minimum function. (a) Write a function that takes two integers and returns the value of the smaller one. In the main() function provide 5 test cases to verify its correctness. (b) Write the function that takes two characters and return the smaller one in the lexicographical order. Write the main() function that tests that functions for 5 different pairs of character type variables. (c) Write a generic function that takes two numeric objects and returns the value of...
PYTHON: Write a function insertInOrder that takes in a list and a number. This function should...
PYTHON: Write a function insertInOrder that takes in a list and a number. This function should assume that the list is already in ascending order. The function should insert the number into the correct position of the list so that the list stays in ascending order. It should modify the list, not build a new list. It does not need to return the list, because it is modifying it.   Hint: Use a whlie loop and list methods lst = [1,3,5,7]...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT