In: Computer Science
Ask the user to enter a basketball player’s free throw percentage, eg. 70%. Your program will simulate the player playing 5 games, each game making 10 free throws. Display the result of the free throws in each game. At the end, print a summary that shows the best/worst game for this player, and the average free throw percentage of the 5 games. Question: How do you simulate a 70% free throw shooter making a free throw? Hint: How about generating a number between 0-100, and checking if that number is less than or equal to 70. If so, you just made a free throw!
Find the code in Python below:
import random
print("Enter the user's free throw percentage = ")
freethrow = int(input())
sum1 = 0
max1=0
min1=100
for i in range(5):
for x in range(10):
randno = random.randint(1,101)
if randno<=freethrow:
sum1 = sum1 + randno
if randno>max1:
max1=randno
if randno<min1:
min1=randno
avg = sum1/50
print("Average freethrow percentage = " + avg)
print("Best Game = " + max1)
print("Worst Game = " + min1)