MCPcopy Index your code
hub / github.com/geekcomputers/Python / main

Function main

russian_roulette.py:10–94  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

8
9
10def main():
11 # create the gun and set the bullet
12 numOfRounds = 6
13 gun = [0, 0, 0, 0, 0, 0]
14 bullet = randrange(0, 6)
15 gun[bullet] = 1
16 player = False # is player dead
17 pc = False # is pc dead
18
19 # menu
20 print("/********************************/")
21 print(" Welcome to russian roulette")
22 print("/********************************/")
23 time.sleep(2)
24 print("you are going to play against the pc")
25 time.sleep(2)
26 print("there is one gun and one bullet")
27 time.sleep(2)
28 print("all you have to do is pick who starts first")
29 time.sleep(2)
30
31 # take input from the user
32 answer = input(
33 "please press 'm' if you want to start first or 'p' if you want the pc to start first: "
34 )
35
36 # check input
37 while answer != "m" and answer != "p":
38 answer = input("please enter again ('m' or 'p'): ")
39
40 # set turn
41 if answer == "m":
42 turn = "player"
43 else:
44 turn = "pc"
45
46 # game starts
47 while numOfRounds != 0 and (pc == False and player == False):
48 print(f"\nRound number {numOfRounds}/6")
49 time.sleep(1)
50 print("the gun is being loaded")
51 time.sleep(3)
52 print(
53 "the gun is placed on "
54 + ("your head" if turn == "player" else "the cpu of the pc")
55 )
56 time.sleep(3)
57 print("and...")
58 time.sleep(1)
59 print("...")
60 time.sleep(2)
61 print("...")
62 time.sleep(2)
63 print("...")
64 time.sleep(2)
65
66 # get the bullet in the chamber
67 shot = gun.pop(numOfRounds - 1)

Callers 1

Calls 1

popMethod · 0.45

Tested by

no test coverage detected