Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/random pass gen #30

Closed
wants to merge 14 commits into from
294 changes: 148 additions & 146 deletions Small Projects/Python/Black Jack/run.py
Original file line number Diff line number Diff line change
@@ -1,186 +1,188 @@
import random
import os


money = 1000


def pick_card():
# Choose a random index
random_index = random.randrange(len(list_card))

# Get the random number
random_number = list_card[random_index]

# Remove the selected number from the list
list_card.remove(random_number)
random_number = list_card.pop(random_index)
return random_number


def print_stats(computer, user):
print(f"computer: [{computer[0]}, *] ")
print(f"user : {user} = sum {card_sum(user)} ")
print(f"Your wallet fund is ${money}")
if computer:
print(f"Computer: {computer} = Sum {card_sum(computer)}")
else:
print("Computer: []")

print(f"User: {user} = Sum {card_sum(user)} ")
print(f"Your Wallet Fund: ${money}")


def card_sum(cards):
return sum(cards)

def card_sum(list):
return sum(list)

def skip_computer():
while card_sum(computer) <= 17:
computer.append(pick_card())


exit = True
while money> 0 or not exit:
list_card = [11,2,3,4,5,6,7,8,9,10,10,10,10,
11,2,3,4,5,6,7,8,9,10,10,10,10,
11,2,3,4,5,6,7,8,9,10,10,10,10,
11,2,3,4,5,6,7,8,9,10,10,10,10]


def display_winner():
global money
if card_sum(computer) == card_sum(user):
print(f"Match Draw: Computer-{computer} and User-{user}")
money += pot / 2
elif card_sum(computer) > 21 or (21 >= card_sum(user) > card_sum(computer)):
print(f"User Wins: ${pot}")
money += pot
else:
print("Computer Wins!")


def play_again():
return input("Play Again? (y/n):").lower() == "y"


exit_game = False

while money > 0 and not exit_game:
list1 = [11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10]
list2 = [11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10]
list3 = [11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10]
list4 = [11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10]
list_card = list1 + list2 + list3 + list4

user = []
computer = []
print(f"Your wallet fund is {money}")
pot = int(input("Enter the Starting bet: "))
computer = [pick_card()]

print(f"Your Wallet Fund: ${money}")
pot = int(input("Enter the Starting Bet: "))

if pot > money:
print("You dont have enough Money in Wallet")
print("You don't have enough money in your wallet")
continue
money -= pot
pot = pot * 2
print(f"Your wallet fund is ${money}")
print(f"Table: ${pot}")

money -= pot
pot *= 2

print_stats(computer, user)

computer.append(pick_card())
user.append(pick_card())
computer.append(pick_card())
user.append(pick_card())

if card_sum(computer) == 22:
computer.remove(11)
computer.append(1)

if card_sum(user) == 22:
user.remove(11)
user.append(1)
print_stats(computer,user)
if (card_sum(computer) == 21 or card_sum(user) == 21) and card_sum(computer) != card_sum(user):
if card_sum(computer) == 21:
print(f"Computer Wins Blackjack: ${pot}")
print(f"computer: {computer} = sum {card_sum(computer)}")
print(f"user : {user} = sum {card_sum(user)} ")
if input("Play Again? : y or n:-") == "y":

print_stats(computer, user)

if card_sum(computer) == 21 or card_sum(user) == 21:
display_winner()
if play_again():
continue
else:
exit_game = True
break

while True:
choice = int(
input(
"""
1. Hit
2. Double
3. Stand
Enter Choice Number: """
)
)

if choice == 1:
user.append(pick_card())
if card_sum(user) < 21:
print_stats(computer, user)
continue
else:
print("Game Over!")
display_winner()
exit_game = True
break
else:
money += pot
print(f"User Wins Blackjack: ${pot}")
print(f"computer: {computer} = sum {card_sum(computer)}")
print(f"user : {user} = sum {card_sum(user)} ")
if input("Play Again? : y or n:-") == "y":
elif choice == 2:
amount = pot / 2
if amount > money:
print("You don't have enough money in your wallet.")
continue
else:
break
elif card_sum(computer) == card_sum(user):
print(f"Match Draw:")
print(f"computer: {computer} = sum {card_sum(computer)}")
print(f"user : {user} = sum {card_sum(user)} ")
money += pot/2

else:
game_continue = True
while game_continue:
choice = int(input('''
1. Hit
2. Duble
3. Stand
Enter Choice Number: '''))


match choice:
case 1:
user.append(pick_card())
if card_sum(user) < 21:
print_stats(computer, user)
continue
case 2:
amount = pot/2
if amount > money:
print("You dont have enough Money in Wallet")
continue
else:
money -= amount
pot = pot * 2
user.append(pick_card())
if card_sum(user) > 21:
print("Game Over")
print(f"computer: {computer} = sum {card_sum(computer)}")
print(f"user : {user} = sum {card_sum(user)} ")
if input("Play Again? : y or n:- ") == "y":
game_continue = False
else:
exit = False
elif card_sum(user) == 21:
skip_computer()
if 21 >= card_sum(user) > card_sum(computer):
money += pot
print(f"User Wins Blackjack: ${pot}")
print(f"computer: {computer} = sum {card_sum(computer)}")
print(f"user : {user} = sum {card_sum(user)} ")
if input("Play Again? : y or n:- ") == "y":
game_continue = False
else:
exit = False
case 3:
skip_computer()
case _:
print(f"Wrong Input: {choice}")
continue

if card_sum(user) > 21:
print("Game Over")
print(f"computer: {computer} = sum {card_sum(computer)}")
print(f"user : {user} = sum {card_sum(user)} ")
if input("Play Again? : y or n:- ") == "y":
money -= amount
pot *= 2
user.append(pick_card())
if card_sum(user) > 21:
print("Game Over!")
display_winner()
exit_game = True
break
else:
exit = False

elif card_sum(user) == 21:
skip_computer()
display_winner()
if play_again():
break
else:
exit_game = True
break
elif choice == 3:
skip_computer()



if card_sum(computer) == card_sum(user):
print(f"Match Draw: computer-{computer} and user-{user}")
money += pot/2
print(f"computer: {computer} = sum {card_sum(computer)}")
print(f"user : {user} = sum {card_sum(user)} ")
if input("Play Again? : y or n:- ") == "y":
game_continue = False
else:
exit = False
elif card_sum(computer) > 21:
print(f"User Win : ${pot}")
money += pot
print(f"computer: {computer} = sum {card_sum(computer)}")
print(f"user : {user} = sum {card_sum(user)} ")
if input("Play Again? : y or n:- ") == "y":
game_continue = False
else:
exit = False
elif 21 >= card_sum(user) > card_sum(computer):
print(f"User Win : ${pot}")
money += pot
print(f"computer: {computer} = sum {card_sum(computer)}")
print(f"user : {user} = sum {card_sum(user)} ")
if input("Play Again? : y or n:- ") == "y":
game_continue = False
else:
exit = False
display_winner()
if play_again():
break
else:
exit_game = True
break
else:
print(f"Wrong Input: {choice}")
continue

skip_computer()

if card_sum(computer) == card_sum(user):
print(f"Match Draw: Computer-{computer} and User-{user}")
money += pot / 2
display_winner()
if play_again():
break
else:
exit_game = True
break
elif card_sum(computer) > 21:
print(f"User Wins: ${pot}")
money += pot
display_winner()
if play_again():
break
else:
print("Game Over")
print(f"computer: {computer} = sum {card_sum(computer)}")
print(f"user : {user} = sum {card_sum(user)} ")
if input("Play Again? : y or n:- ") == "y":
game_continue = False
else:
exit = False
os.system("cls")
exit_game = True
break
elif 21 >= card_sum(user) > card_sum(computer):
print(f"User Wins: ${pot}")
money += pot
display_winner()
if play_again():
break
else:
exit_game = True
break
else:
print("Game Over!")
display_winner()
if play_again():
break
else:
exit_game = True
break

os.system("cls")
2 changes: 1 addition & 1 deletion Small Projects/Python/Calculator/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@
result = num1 / num2
print("Result: " + str(result))
else:
print("Invalid input. Please try again.")
print("Invalid input. Please try again.")
39 changes: 29 additions & 10 deletions Small Projects/Python/Random Pass Gen/run.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,37 @@
import random
import string

ascii_letters = list(string.ascii_letters)
digits = list(string.digits)
punctuations = list(string.punctuation)

mix = [ascii_letters, digits, punctuations]
def generate_password(length, char_types):
characters = []

if "alphanumeric" in char_types:
characters.extend(list(string.ascii_letters + string.digits))

if "digit" in char_types:
characters.extend(list(string.digits))

if "punctuation" in char_types:
characters.extend(list(string.punctuation))

if not characters:
print("Please select at least one character type.")
return None

password = "".join(random.choice(characters) for _ in range(length))
return password


length = int(input("Enter the Password Length in numbers: "))

password = ""
i = []
for x in range(0,length):
i = mix[random.randint(0,len(mix)-1)]
password += i[random.randint(0,len(i)-1)]
selected_char_types = []
while not selected_char_types:
selected_char_types = input(
"Select character types (alphanumeric, digit, punctuation) separated by commas: "
).split(",")
selected_char_types = [s.strip().lower() for s in selected_char_types]

password = generate_password(length, selected_char_types)

print(f"your password is: {password}")
if password:
print(f"Your password is: {password}")