Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import random
- def main():
- ptsA = 0
- ptsB = 0
- gameClock = 15*60
- whoHasBall = 'a'
- while (gameClock > 0):
- #distance = int(input('How far from basket? '))
- distance = random.randint(3,30)
- print(f'Team {whoHasBall} shoots the ball from {distance} feet!')
- result = shoot(distance)
- if result > 0:
- if whoHasBall == 'a':
- ptsA += result
- else:
- ptsB += result
- print(f'Score! Score is now {ptsA}-{ptsB}.')
- if whoHasBall == 'a':
- whoHasBall = 'b'
- else:
- whoHasBall = 'a'
- else:
- print('Miss!')
- rebound = random.randint(1,4)
- if rebound == 1:
- print(f'Team {whoHasBall} keeps the ball!')
- else:
- if whoHasBall == 'a':
- whoHasBall = 'b'
- else:
- whoHasBall = 'a'
- gameClock = gameClock - random.randint(10,24)
- print(f'{gameClock} seconds left on the clock')
- print()
- time.sleep(.1)
- print('Game over')
- print(f'Final score is {ptsA}-{ptsB}.')
- def shoot(d):
- pct = (90*.95**d)/100
- #print(d, pct)
- num = random.random()
- if num < pct:
- if d>24:
- return 3
- else:
- return 2
- else:
- return 0
- main()
Advertisement
Add Comment
Please, Sign In to add comment