Skip to content

Commit 10fefe4

Browse files
Merge pull request geekcomputers#1516 from Ataba29/master
Merge
2 parents d145c84 + ede76e7 commit 10fefe4

File tree

2 files changed

+128
-0
lines changed

2 files changed

+128
-0
lines changed

recursiveStrings.py

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
""" author: Ataba29
2+
code has a matrix each list inside of the matrix has two strings
3+
the code determines if the two strings are similar or different
4+
from each other recursively
5+
"""
6+
7+
8+
def CheckTwoStrings(str1, str2):
9+
# function takes two strings and check if they are similar
10+
# returns True if they are identical and False if they are different
11+
12+
if(len(str1) != len(str2)):
13+
return False
14+
if(len(str1) == 1 and len(str2) == 1):
15+
return str1[0] == str2[0]
16+
17+
return (str1[0] == str2[0]) and CheckTwoStrings(str1[1:], str2[1:])
18+
19+
20+
def main():
21+
matrix = [["hello", "wow"], ["ABSD", "ABCD"],
22+
["List", "List"], ["abcspq", "zbcspq"],
23+
["1263", "1236"], ["lamar", "lamars"],
24+
["amczs", "amczs"], ["yeet", "sheesh"], ]
25+
26+
for i in matrix:
27+
if CheckTwoStrings(i[0], i[1]):
28+
print(f"{i[0]},{i[1]} are similar")
29+
else:
30+
print(f"{i[0]},{i[1]} are different")
31+
32+
33+
main()

russian_roulette.py

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
""" author: Ataba29
2+
the code is just a russian roulette game against
3+
the computer
4+
"""
5+
from random import randrange
6+
import time
7+
8+
9+
def main():
10+
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("the gun is placed on " + ("your head" if turn ==
53+
"player" else "the cpu of the pc"))
54+
time.sleep(3)
55+
print("and...")
56+
time.sleep(1)
57+
print("...")
58+
time.sleep(2)
59+
print("...")
60+
time.sleep(2)
61+
print("...")
62+
time.sleep(2)
63+
64+
# get the bullet in the chamber
65+
shot = gun.pop(numOfRounds - 1)
66+
67+
if shot:
68+
print("THE GUN WENT OFF!!!")
69+
print("YOU DIED" if turn == "player" else "THE PC DIED")
70+
if turn == "player": # set up who died
71+
player = True
72+
else:
73+
pc = True
74+
else:
75+
print("nothing happened phew!")
76+
if turn == "player": # flip the turn
77+
turn = "pc"
78+
else:
79+
turn = "player"
80+
81+
time.sleep(2)
82+
numOfRounds -= 1
83+
84+
time.sleep(1)
85+
print("")
86+
if player:
87+
print("sorry man you died better luck next time")
88+
print("don't forget to send a pic from heaven :)")
89+
else:
90+
print("good job man you survived")
91+
print("you just got really lucky")
92+
print("anyways hope you had fun because i sure did")
93+
94+
95+
main()

0 commit comments

Comments
 (0)