-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathkmalhotra08 BasketballGame
44 lines (39 loc) · 1.04 KB
/
kmalhotra08 BasketballGame
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import random
def shoot():
shot_result = random.randint(0, 1)
return shot_result
def main():
player_score = 0
computer_score = 0
while True:
print("Basketball Game")
print("1. Shoot")
print("2. Quit")
choice = input("Enter your choice: ")
if choice == "1":
result = shoot()
if result == 1:
print("Swish! You made the shot!")
player_score += 2
else:
print("Oops, you missed the shot.")
computer_result = shoot()
if computer_result == 1:
print("The computer made the shot!")
computer_score += 2
else:
print("The computer missed the shot.")
elif choice == "2":
break
else:
print("Invalid choice. Please select 1 to shoot or 2 to quit.")
print("Final Score:")
print(f"You: {player_score}")
print(f"Computer: {computer_score}")
if player_score > computer_score:
print("You win!")
elif player_score < computer_score:
print("The computer wins!")
else: print("It's a tie!")
if __name__ == "__main__":
main()