Skip to content

Commit 99b15b7

Browse files
authored
Merge branch 'geekcomputers:master' into master
2 parents f673191 + 85cc5bc commit 99b15b7

File tree

3 files changed

+110
-149
lines changed

3 files changed

+110
-149
lines changed
Lines changed: 15 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,20 @@
1-
# master
2-
def num(a):
3-
# initialising starting number
1+
def print_pattern(rows: int) -> None:
2+
for i in range(1, rows + 1):
3+
print("".join(str(j) for j in range(1, i + 1)))
44

5-
num = 1
65

7-
# outer loop to handle number of rows
6+
def start():
7+
while True:
8+
try:
9+
n = int(input("Enter number of rows: "))
10+
if n < 1:
11+
print("Invalid value, enter a positive integer.")
12+
continue
13+
break
14+
except ValueError:
15+
print("Invalid input, please enter a number.")
816

9-
for i in range(0, a):
10-
# re assigning num
17+
print_pattern(n)
1118

12-
num = 1
1319

14-
# inner loop to handle number of columns
15-
16-
# values changing acc. to outer loop
17-
18-
for k in range(0, i + 1):
19-
# printing number
20-
21-
print(num, end=" ")
22-
23-
# incrementing number at each column
24-
25-
num = num + 1
26-
27-
# ending line after each row
28-
29-
print("\r")
30-
31-
32-
# Driver code
33-
34-
a = 5
35-
36-
num(a)
37-
# =======
38-
# 1-12-123-1234 Pattern up to n lines
39-
40-
n = int(input("Enter number of rows: "))
41-
42-
for i in range(1, n + 1):
43-
for j in range(1, i + 1):
44-
print(j, end="")
45-
print()
46-
47-
# master
20+
start()

blackjack.py

Lines changed: 81 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -4,104 +4,102 @@
44

55
deck = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 11] * 4
66

7-
random.shuffle(deck)
8-
9-
print(
10-
" ********************************************************** "
11-
)
12-
print(
13-
" Welcome to the game Casino - BLACK JACK ! "
14-
)
15-
print(
16-
" ********************************************************** "
17-
)
18-
19-
d_cards = [] # Initialising dealer's cards
20-
p_cards = [] # Initialising player's cards
21-
22-
while len(d_cards) != 2:
23-
random.shuffle(deck)
24-
d_cards.append(deck.pop())
25-
if len(d_cards) == 2:
26-
print("The cards dealer has are X ", d_cards[1])
27-
28-
# Displaying the Player's cards
29-
while len(p_cards) != 2:
30-
random.shuffle(deck)
31-
p_cards.append(deck.pop())
32-
if len(p_cards) == 2:
33-
print("The total of player is ", sum(p_cards))
34-
print("The cards Player has are ", p_cards)
35-
36-
if sum(p_cards) > 21:
37-
print("You are BUSTED !\n **************Dealer Wins !!******************\n")
38-
exit()
397

40-
if sum(d_cards) > 21:
8+
def welcome():
9+
print(
10+
" ********************************************************** "
11+
)
12+
print(
13+
" Welcome to the game Casino - BLACK JACK ! "
14+
)
4115
print(
42-
"Dealer is BUSTED !\n ************** You are the Winner !!******************\n"
16+
" ********************************************************** "
4317
)
44-
exit()
4518

46-
if sum(d_cards) == 21:
47-
print("***********************Dealer is the Winner !!******************")
48-
exit()
4919

50-
if sum(d_cards) == 21 and sum(p_cards) == 21:
51-
print("*****************The match is tie !!*************************")
52-
exit()
20+
def start_game():
21+
random.shuffle(deck)
5322

23+
d_cards = []
24+
p_cards = []
5425

55-
def dealer_choice():
56-
if sum(d_cards) < 17:
57-
while sum(d_cards) < 17:
58-
random.shuffle(deck)
59-
d_cards.append(deck.pop())
26+
# Dealer initial cards
27+
while len(d_cards) != 2:
28+
random.shuffle(deck)
29+
d_cards.append(deck.pop())
30+
if len(d_cards) == 2:
31+
print("The cards dealer has are X ", d_cards[1])
32+
33+
# Player initial cards
34+
while len(p_cards) != 2:
35+
random.shuffle(deck)
36+
p_cards.append(deck.pop())
37+
if len(p_cards) == 2:
38+
print("The total of player is ", sum(p_cards))
39+
print("The cards Player has are ", p_cards)
6040

61-
print("Dealer has total " + str(sum(d_cards)) + "with the cards ", d_cards)
41+
if sum(p_cards) > 21:
42+
print("You are BUSTED !\n **************Dealer Wins !!******************\n")
43+
return
6244

63-
if sum(p_cards) == sum(d_cards):
64-
print("***************The match is tie !!****************")
65-
exit()
45+
if sum(d_cards) > 21:
46+
print(
47+
"Dealer is BUSTED !\n ************** You are the Winner !!******************\n"
48+
)
49+
return
50+
51+
if sum(d_cards) == 21 and sum(p_cards) == 21:
52+
print("*****************The match is tie !!*************************")
53+
return
6654

6755
if sum(d_cards) == 21:
68-
if sum(p_cards) < 21:
69-
print("***********************Dealer is the Winner !!******************")
70-
elif sum(p_cards) == 21:
71-
print("********************There is tie !!**************************")
72-
else:
73-
print("***********************Dealer is the Winner !!******************")
56+
print("***********************Dealer is the Winner !!******************")
57+
return
7458

75-
elif sum(d_cards) < 21:
76-
if sum(p_cards) < 21 and sum(p_cards) < sum(d_cards):
77-
print("***********************Dealer is the Winner !!******************")
78-
if sum(p_cards) == 21:
79-
print("**********************Player is winner !!**********************")
80-
if sum(p_cards) < 21 and sum(p_cards) > sum(d_cards):
81-
print("**********************Player is winner !!**********************")
59+
def dealer_choice():
60+
if sum(d_cards) < 17:
61+
while sum(d_cards) < 17:
62+
random.shuffle(deck)
63+
d_cards.append(deck.pop())
64+
65+
print("Dealer has total " + str(sum(d_cards)) + " with the cards ", d_cards)
8266

83-
else:
84-
if sum(p_cards) < 21:
67+
if sum(p_cards) == sum(d_cards):
68+
print("***************The match is tie !!****************")
69+
return
70+
71+
if sum(d_cards) > 21:
8572
print("**********************Player is winner !!**********************")
86-
elif sum(p_cards) == 21:
73+
return
74+
75+
if sum(d_cards) > sum(p_cards):
76+
print("***********************Dealer is the Winner !!******************")
77+
else:
8778
print("**********************Player is winner !!**********************")
79+
80+
# Player turn
81+
while sum(p_cards) < 21:
82+
k = input("Want to hit or stay?\n Press 1 for hit and 0 for stay ")
83+
84+
if k == "1":
85+
random.shuffle(deck)
86+
p_cards.append(deck.pop())
87+
print("You have a total of " + str(sum(p_cards)) + " with the cards ", p_cards)
88+
89+
if sum(p_cards) > 21:
90+
print("*************You are BUSTED !*************\n Dealer Wins !!")
91+
return
92+
93+
if sum(p_cards) == 21:
94+
print(
95+
"*******************You are the Winner !!*****************************"
96+
)
97+
return
8898
else:
89-
print("***********************Dealer is the Winner !!******************")
99+
dealer_choice()
100+
break
90101

91102

92-
while sum(p_cards) < 21:
93-
k = input("Want to hit or stay?\n Press 1 for hit and 0 for stay ")
94-
if k == 1:
95-
random.shuffle(deck)
96-
p_cards.append(deck.pop())
97-
print("You have a total of " + str(sum(p_cards)) + " with the cards ", p_cards)
98-
if sum(p_cards) > 21:
99-
print("*************You are BUSTED !*************\n Dealer Wins !!")
100-
if sum(p_cards) == 21:
101-
print(
102-
"*******************You are the Winner !!*****************************"
103-
)
104-
105-
else:
106-
dealer_choice()
107-
break
103+
# Run Game
104+
welcome()
105+
start_game()

scrap_file.py

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,23 @@
66
import requests
77

88

9-
# Function for download file parameter taking as url
10-
9+
def download(url, filename):
10+
try:
11+
with requests.get(url, stream=True, timeout=10) as response:
12+
response.raise_for_status() # Raises error for 4xx/5xx
1113

12-
def download(url):
13-
f = open(
14-
"file_name.jpg", "wb"
15-
) # opening file in write binary('wb') mode with file_name.ext ext=extension
16-
f.write(requests.get(url).content) # Writing File Content in file_name.jpg
17-
f.close()
18-
print("Succesfully Downloaded")
14+
with open(filename, "wb") as file:
15+
for chunk in response.iter_content(chunk_size=8192):
16+
if chunk:
17+
file.write(chunk)
1918

19+
print(f"Successfully downloaded: {filename}")
2020

21-
# Function is do same thing as method(download) do,but more strict
22-
def download_2(url):
23-
try:
24-
response = requests.get(url)
25-
except Exception:
26-
print("Failed Download!")
27-
else:
28-
if response.status_code == 200:
29-
with open("file_name.jpg", "wb") as f:
30-
f.write(requests.get(url).content)
31-
print("Succesfully Downloaded")
32-
else:
33-
print("Failed Download!")
21+
except requests.exceptions.RequestException as e:
22+
print(f"Download failed: {e}")
3423

3524

36-
url = "https://avatars0.githubusercontent.com/u/29729380?s=400&v=4" # URL from which we want to download
25+
# Example usage
26+
url = "https://avatars0.githubusercontent.com/u/29729380?s=400&v=4"
27+
download(url, "avatar.jpg")
3728

38-
download(url)

0 commit comments

Comments
 (0)