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 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...
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]...
Write a Python function that takes a list of string as arguments. When the function is...
Write a Python function that takes a list of string as arguments. When the function is called it should ask the user to make a selection from the options listed in the given list. The it should get input from the user. Place " >" in front of user input. if the user doesn't input one of the given choices, then the program should repeatedly ask the user to pick from the list. Finally, the function should return the word...
Q6: (Sides of a Right Triangle) Write a function that reads three nonzero integers and determines...
Q6: (Sides of a Right Triangle) Write a function that reads three nonzero integers and determines whether they are the sides of a right-angled triangle. The function should take three integer arguments and return 1 (true) if the arguments comprise a right-angled triangle, and 0 (false) otherwise. Use this function in a program that inputs a series of sets of integers. Hint: a^2+b^2=C^2 Codes in C please.s
Q6: (Sides of a Right Triangle) Write a function that reads three nonzero integers and determines...
Q6: (Sides of a Right Triangle) Write a function that reads three nonzero integers and determines whether they are the sides of a right-angled triangle. The function should take three integer arguments and return 1 (true) if the arguments comprise a right-angled triangle, and 0 (false) otherwise. Use this function in a program that inputs a series of sets of integers. Hint: a^2+b^2=C^2
Write a function named findIndex that takes an array of integers, the number of elements in...
Write a function named findIndex that takes an array of integers, the number of elements in the array, and two variables, such that it changes the value of the first to be the index of the smallest element in the array, and changes the value of the second to be the index of the largest element in the array. Please complete this in C++, using pass by reference
Write a function named findIndex that takes an array of integers, the number of elements in...
Write a function named findIndex that takes an array of integers, the number of elements in the array, and two variables, such that it changes the value of the first to be the index of the smallest element in the array, and changes the value of the second to be the index of the largest element in the array. Please complete this in C++
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT