i used python 3 and i am new to it so please help would prefer if you do it in p
ID: 3799025 • Letter: I
Question
i used python 3 and i am new to it so please help would prefer if you do it in python 3 and send me picture
C) Write a function ‘sumOfThrows’ that takes two parameters ‘throws’ and ‘sides’. ‘sides’ should have a default values of 6. The function should return the sum from doing however many random throws specified for a die with ‘sides’ number of sides.
Test the function.
For example sumOfThrows(1,6) should show the outcome of throwing one six-sided die.
sumOfThrows(3,8) should show the outcome of throwing three dice with sides numbered 1 through 8.
sumOfThrows(2) should show the outcome of throwing two six-sided dice.
Explanation / Answer
Here is the function for you:
'''Write a function 'sumOfThrows' that takes two parameters 'throws' and 'sides'.
'sides' should have a default values of 6.
The function should return the sum from doing however many random throws specified for a
die with 'sides' number of sides.'''
def sumOfThrows(throws, sides = 6):
sum = 0
import random
for i in range(throws):
value = random.randint(1,sides)
sum += value
print value,
print ':',
return sum
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.