Skip to content

Commit adf1951

Browse files
committed
initial commit
0 parents  commit adf1951

File tree

4 files changed

+411
-0
lines changed

4 files changed

+411
-0
lines changed

hand-cricket.py

+201
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
import random
2+
import copy
3+
import sys
4+
chosen = ''
5+
session = 0
6+
user = 0
7+
dev = 0
8+
coin = ['head' , 'tail']
9+
choices = ['bat' , 'bowl' , 'bat']
10+
11+
print('Welcome to HANDCRICKET....\nThr program replicates the classic handcricket game....\nRules:\nFirst a toss is held .. if u win u are given the chance to bowl or bat..\nIf ur score is greater than that of computer..u lose\n')
12+
13+
def get_int(prompt):
14+
while True:
15+
try:
16+
value = int(input(prompt))
17+
break
18+
except ValueError:
19+
print("\nSorry, I didn't understand that.\n")
20+
continue
21+
22+
return value
23+
24+
while True:
25+
val = get_int('How many wickets u want in the game')
26+
if val <= 0:
27+
print('Enter either 1 or 0')
28+
else:
29+
break
30+
31+
wicket = copy.deepcopy(val)
32+
while True:
33+
34+
ov = get_int('How many overs U want in the game')
35+
if ov <= 0:
36+
print('Over must be greater than 0')
37+
else:
38+
break
39+
40+
overs = copy.deepcopy(ov)
41+
i = 0
42+
j = 0
43+
44+
45+
picked = get_int('Would You Pick Head or Tails \n [0] for heads , [1] for tails')
46+
47+
def toss():
48+
global chosen
49+
global compchoice
50+
result = coin[random.randint(0 , 1)]
51+
print(result)
52+
if coin.index(result) == picked:
53+
print('\nYou Won The Toss')
54+
chosen = choices[get_int('Would U Like To Bat Or Bowl , [0] for bat , [1] for bowl\n')]
55+
print(f'\nYou chose to {chosen}\n')
56+
57+
else:
58+
print('\nYou Lost The Toss...Computer Won')
59+
chosen = choices[random.randint(0 , 1)]
60+
61+
print(f'\nComputer chose to { choices[choices.index(chosen)+1]}')
62+
print(f'You Will {chosen}\n')
63+
print()
64+
65+
66+
def checkSession():
67+
global session
68+
global user
69+
global dev
70+
if session == 1:
71+
if chosen == 'bat':
72+
if user > dev:
73+
print(f'overs remaining {overs}\n')
74+
print(f'You won ... Your end score was {user} ... Congrats..\nThanks for playing\n')
75+
sys.exit()
76+
else:
77+
if dev > user:
78+
print(f'overs remaining {overs}\n')
79+
print(f'You Lost ... Computer Won....Your end score was {user}\n')
80+
sys.exit()
81+
82+
if session == 2:
83+
if user > dev:
84+
print(f'overs remaining {overs}\n')
85+
print(f'You won ... Your end score was {user} ... Congrats..\nThanks for playing\n')
86+
sys.exit()
87+
elif user < dev:
88+
print(f'overs remaining {overs}\n')
89+
print(f'You Lost ... Computer Won....Your end score was {user}\n')
90+
sys.exit()
91+
92+
93+
94+
95+
96+
def handcricket():
97+
global i
98+
global wicket
99+
global user
100+
global dev
101+
global session
102+
global chosen
103+
global overs
104+
global j
105+
global val
106+
global ov
107+
j+=1
108+
if overs < ov or j!=1:
109+
i+=1
110+
checkSession()
111+
if overs == 0 :
112+
113+
i = -1
114+
session += 1
115+
if session == 2:
116+
checkSession()
117+
overs = copy.deepcopy(ov)
118+
wicket = copy.deepcopy(val)
119+
if chosen == 'bat':
120+
chosen = 'bowl'
121+
print('\n\nEnd of Innings\n\nEnd of Batting...Get ready to bowl\n\n')
122+
123+
print(f'Your Score is {user}\nComputers score is {dev}\n')
124+
elif chosen == 'bowl':
125+
chosen = 'bat'
126+
print('\n\nEnd of innings\n\nEnd of Bowling...Get ready to bat\n\n')
127+
print(f'Your score is {user}\nComputers score is {dev}\n')
128+
129+
handcricket()
130+
131+
if i // 6 == 1:
132+
overs -= 1
133+
i = -1
134+
print(f'End of one over , remaining {overs}\n')
135+
handcricket()
136+
137+
138+
139+
if wicket == 0:
140+
session += 1
141+
print(f'All wickets are gone\n{overs} overs were remaining\n')
142+
if session == 2:
143+
checkSession()
144+
145+
overs = copy.deepcopy(ov)
146+
i=-1
147+
wicket = copy.deepcopy(val)
148+
if chosen == 'bat' :
149+
print('\n\nEnd of innings\n\nEnd of Batting...Get ready to bowl\n\n')
150+
151+
print(f'Your Score is {user}\nComputers score is {dev}\n')
152+
chosen = 'bowl'
153+
handcricket()
154+
155+
156+
elif chosen == 'bowl':
157+
print('\n\nEnd of innings\n\nEnd of Bowling...Get ready to bat\n\n')
158+
print(f'Your score is {user}\nComputers score is {dev}\n')
159+
chosen = 'bat'
160+
handcricket()
161+
162+
163+
164+
165+
player = get_int('Chose a number from 1 to 6\n')
166+
if player > 6 or player < 1:
167+
print('number must be greater than one and smaller than 6 \n')
168+
i -= 1
169+
handcricket()
170+
print(f'You Chose {player}\n')
171+
comp = random.randint(1 , 6)
172+
print(f'Computer Chose {comp}\n')
173+
174+
175+
176+
if player == comp:
177+
wicket -= 1
178+
print('wicket\n')
179+
if chosen == 'bat':
180+
print(f'You lost a wicket , remaining wickets = {wicket} \n Ur Score is {user}\n')
181+
handcricket()
182+
else:
183+
print(f'Computer Lost a wicket , remaining {wicket}\n')
184+
handcricket()
185+
186+
else:
187+
188+
189+
if chosen == 'bat':
190+
user += player
191+
print(f'Players score is {user}\n')
192+
handcricket()
193+
else:
194+
dev += comp
195+
print(f'Computers score is {dev}\n')
196+
handcricket()
197+
198+
199+
200+
toss()
201+
handcricket()

hangman.py

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
from more_itertools import locate
2+
import random
3+
import sys
4+
5+
6+
lst = ['arbitrary' ,'bald','hello' , 'difficult' , 'dictionary' , 'musicbreathren' , 'genre' , 'ambition' , 'python' , 'snake' , 'game','guitar']
7+
8+
word = lst[random.randint(0 , len(lst) - 1)]
9+
out = '_'*len(word)
10+
i = 0
11+
chances = 6
12+
w = ''.join(word)
13+
14+
print('Hello....Welcome to HANGMAN.. \nThe rules here are simple...\nu are given a random word...\nu have to guess the word by guessing a alphabet in the word... \nFailing 6 times will result the game to be over \nLets begin \n ')
15+
16+
def printHangman(n):
17+
18+
face = ' O'
19+
belly=' |'
20+
leg1=' / '
21+
leg2='\ '
22+
hand1=' \|'
23+
hand2='/'
24+
25+
26+
27+
str = '-----------------\n|{face}\n|{h1}{h2}\n|{b}\n|{l1}{l2}\n|\n|\n|'.format(
28+
face= face if n <6 else '',h1=hand1 if n<5 else '',h2=hand2 if n<4 else '' ,b = belly if n<3 else '',l1 = leg1 if n<2 else '',l2 = leg2 if n<1 else ''
29+
)
30+
print(str)
31+
32+
33+
34+
35+
36+
def hangman():
37+
global word
38+
global out
39+
global chances
40+
if chances == 0:
41+
printHangman(chances)
42+
print(f'You lose..... \nThr word was {word}\nBetter luck next time....')
43+
sys.exit()
44+
45+
out = list(out)
46+
47+
if '_' not in out:
48+
49+
printHangman(chances)
50+
print('\n\nYou won!!! 😎😎😎... Thanks for playing...')
51+
sys.exit()
52+
53+
word = list(word)
54+
print(' '.join(out))
55+
56+
userChar = input('guess a word')
57+
58+
if len(userChar) > 1 or userChar.isalpha() == False:
59+
print('invalid user input..u can only enter a single alphabet as input')
60+
hangman()
61+
62+
elif userChar not in word or userChar in out:
63+
print('wrong guess😑')
64+
chances -=1
65+
printHangman(chances)
66+
print(f'total chances remaining {chances}')
67+
else:
68+
a = list(locate(word, lambda x: x == userChar))
69+
for i in a:
70+
out[i] = userChar
71+
print(' '.join(out))
72+
print('right guess😁')
73+
printHangman(chances)
74+
print(f'total chances remaining {chances}')
75+
76+
while i == 0:
77+
hangman()
78+
79+
80+

password-generator.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import string
2+
import random
3+
import sys
4+
5+
chars = list(string.ascii_letters)
6+
nums = list(string.digits)
7+
punc = list(string.punctuation)
8+
9+
password = []
10+
11+
nchar = int(input('How many chars u want in the password???'))
12+
13+
ndigits = int(input('How many digits u want in the password???'))
14+
15+
npunc = int(input('How many punctuation symbols u want in the password??? '))
16+
total = nchar + ndigits + npunc
17+
18+
if total < 8:
19+
print('the total number of letters for the password must be greater than or equal to 8!!!')
20+
sys.exit()
21+
else:
22+
i = 0
23+
j = 0
24+
k = 0
25+
26+
while i < nchar or j < ndigits or k < npunc:
27+
if i != nchar:
28+
password.append(chars[random.randint(0 , len(chars) - 1)])
29+
i+=1
30+
if j != ndigits:
31+
password.append(nums[random.randint(0 , len(nums) - 1)])
32+
j+=1
33+
if k != npunc:
34+
password.append(punc[random.randint(0 , len(punc) - 1)])
35+
k+=1
36+
37+
print(''.join(random.sample(password, len(password))))

0 commit comments

Comments
 (0)