Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 15 additions & 42 deletions To print series 1,12,123,1234......py
Original file line number Diff line number Diff line change
@@ -1,47 +1,20 @@
# master
def num(a):
# initialising starting number
def print_pattern(rows: int) -> None:
for i in range(1, rows + 1):
print("".join(str(j) for j in range(1, i + 1)))

num = 1

# outer loop to handle number of rows
def start():
while True:
try:
n = int(input("Enter number of rows: "))
if n < 1:
print("Invalid value, enter a positive integer.")
continue
break
except ValueError:
print("Invalid input, please enter a number.")

for i in range(0, a):
# re assigning num
print_pattern(n)

num = 1

# inner loop to handle number of columns

# values changing acc. to outer loop

for k in range(0, i + 1):
# printing number

print(num, end=" ")

# incrementing number at each column

num = num + 1

# ending line after each row

print("\r")


# Driver code

a = 5

num(a)
# =======
# 1-12-123-1234 Pattern up to n lines

n = int(input("Enter number of rows: "))

for i in range(1, n + 1):
for j in range(1, i + 1):
print(j, end="")
print()

# master
start()
164 changes: 81 additions & 83 deletions blackjack.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,104 +4,102 @@

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

random.shuffle(deck)

print(
" ********************************************************** "
)
print(
" Welcome to the game Casino - BLACK JACK ! "
)
print(
" ********************************************************** "
)

d_cards = [] # Initialising dealer's cards
p_cards = [] # Initialising player's cards

while len(d_cards) != 2:
random.shuffle(deck)
d_cards.append(deck.pop())
if len(d_cards) == 2:
print("The cards dealer has are X ", d_cards[1])

# Displaying the Player's cards
while len(p_cards) != 2:
random.shuffle(deck)
p_cards.append(deck.pop())
if len(p_cards) == 2:
print("The total of player is ", sum(p_cards))
print("The cards Player has are ", p_cards)

if sum(p_cards) > 21:
print("You are BUSTED !\n **************Dealer Wins !!******************\n")
exit()

if sum(d_cards) > 21:
def welcome():
print(
" ********************************************************** "
)
print(
" Welcome to the game Casino - BLACK JACK ! "
)
print(
"Dealer is BUSTED !\n ************** You are the Winner !!******************\n"
" ********************************************************** "
)
exit()

if sum(d_cards) == 21:
print("***********************Dealer is the Winner !!******************")
exit()

if sum(d_cards) == 21 and sum(p_cards) == 21:
print("*****************The match is tie !!*************************")
exit()
def start_game():
random.shuffle(deck)

d_cards = []
p_cards = []

def dealer_choice():
if sum(d_cards) < 17:
while sum(d_cards) < 17:
random.shuffle(deck)
d_cards.append(deck.pop())
# Dealer initial cards
while len(d_cards) != 2:
random.shuffle(deck)
d_cards.append(deck.pop())
if len(d_cards) == 2:
print("The cards dealer has are X ", d_cards[1])

# Player initial cards
while len(p_cards) != 2:
random.shuffle(deck)
p_cards.append(deck.pop())
if len(p_cards) == 2:
print("The total of player is ", sum(p_cards))
print("The cards Player has are ", p_cards)

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

if sum(p_cards) == sum(d_cards):
print("***************The match is tie !!****************")
exit()
if sum(d_cards) > 21:
print(
"Dealer is BUSTED !\n ************** You are the Winner !!******************\n"
)
return

if sum(d_cards) == 21 and sum(p_cards) == 21:
print("*****************The match is tie !!*************************")
return

if sum(d_cards) == 21:
if sum(p_cards) < 21:
print("***********************Dealer is the Winner !!******************")
elif sum(p_cards) == 21:
print("********************There is tie !!**************************")
else:
print("***********************Dealer is the Winner !!******************")
print("***********************Dealer is the Winner !!******************")
return

elif sum(d_cards) < 21:
if sum(p_cards) < 21 and sum(p_cards) < sum(d_cards):
print("***********************Dealer is the Winner !!******************")
if sum(p_cards) == 21:
print("**********************Player is winner !!**********************")
if sum(p_cards) < 21 and sum(p_cards) > sum(d_cards):
print("**********************Player is winner !!**********************")
def dealer_choice():
if sum(d_cards) < 17:
while sum(d_cards) < 17:
random.shuffle(deck)
d_cards.append(deck.pop())

print("Dealer has total " + str(sum(d_cards)) + " with the cards ", d_cards)

else:
if sum(p_cards) < 21:
if sum(p_cards) == sum(d_cards):
print("***************The match is tie !!****************")
return

if sum(d_cards) > 21:
print("**********************Player is winner !!**********************")
elif sum(p_cards) == 21:
return

if sum(d_cards) > sum(p_cards):
print("***********************Dealer is the Winner !!******************")
else:
print("**********************Player is winner !!**********************")

# Player turn
while sum(p_cards) < 21:
k = input("Want to hit or stay?\n Press 1 for hit and 0 for stay ")

if k == "1":
random.shuffle(deck)
p_cards.append(deck.pop())
print("You have a total of " + str(sum(p_cards)) + " with the cards ", p_cards)

if sum(p_cards) > 21:
print("*************You are BUSTED !*************\n Dealer Wins !!")
return

if sum(p_cards) == 21:
print(
"*******************You are the Winner !!*****************************"
)
return
else:
print("***********************Dealer is the Winner !!******************")
dealer_choice()
break


while sum(p_cards) < 21:
k = input("Want to hit or stay?\n Press 1 for hit and 0 for stay ")
if k == 1:
random.shuffle(deck)
p_cards.append(deck.pop())
print("You have a total of " + str(sum(p_cards)) + " with the cards ", p_cards)
if sum(p_cards) > 21:
print("*************You are BUSTED !*************\n Dealer Wins !!")
if sum(p_cards) == 21:
print(
"*******************You are the Winner !!*****************************"
)

else:
dealer_choice()
break
# Run Game
welcome()
start_game()
38 changes: 14 additions & 24 deletions scrap_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,23 @@
import requests


# Function for download file parameter taking as url

def download(url, filename):
try:
with requests.get(url, stream=True, timeout=10) as response:
response.raise_for_status() # Raises error for 4xx/5xx

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

print(f"Successfully downloaded: {filename}")

# Function is do same thing as method(download) do,but more strict
def download_2(url):
try:
response = requests.get(url)
except Exception:
print("Failed Download!")
else:
if response.status_code == 200:
with open("file_name.jpg", "wb") as f:
f.write(requests.get(url).content)
print("Succesfully Downloaded")
else:
print("Failed Download!")
except requests.exceptions.RequestException as e:
print(f"Download failed: {e}")


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

download(url)
Loading