War Card Game

This is a version of the card game War, and it is also my final Python A project.

# War Card game # A player wins if they gain 52 cards or have more cards after 5 rounds. These amounts can be adjusted if needed. # There are 2 checks placed in the code for player and opponent deck contents, these show the movement of cards. # A tie breaker within a tie breaker is decided with a coin flip in this version of the game. from random import randint total_cards = ["2", "2", "2", "2", "3", "3", "3", "3", "4", "4", "4", "4", "5", "5", "5", "5", "6", "6", "6", "6", "7", "7", "7", "7", "8", "8", "8", "8", "9", "9", "9", "9", "10", "10", "10", "10", "11", "11", "11", "11", "12", "12", "12", "12", "13", "13", "13", "13", "14", "14", "14", "14"] player_cards = [] opponent_cards = [] for x in range(0, 26): y = 51-x card_number = randint(0, y) card = total_cards[card_number] player_cards.append(card) total_cards.pop(card_number) for x in range(0, 26): y = 25-x card_number = randint(0, y) card = total_cards[card_number] opponent_cards.append(card) total_cards.pop(card_number) print("player") print(player_cards) print("opponent") print(opponent_cards) # This is a check to see the starting moves, feel free to remove if using the code. p = len(player_cards) o = len(opponent_cards) moves = 0 while p != 52 and o != 52 and moves < 5: p_card = int(player_cards[0]) o_card = int(opponent_cards[0]) print("You have placed down a ", p_card) print("The opponent has placed down a ", o_card) moves = moves + 1 if p_card > o_card: continue_playing = input("Your card is higher, take all cards and keep playing? Enter yes to continue: ") if continue_playing == "yes": player_cards.append(str(o_card)) player_cards.pop(0) player_cards.append(str(p_card)) opponent_cards.pop(0) elif o_card > p_card: continue_playing = input("Your card is lower, give opponent cards and keep playing? Enter yes to continue: ") if continue_playing == "yes": opponent_cards.append(str(p_card)) opponent_cards.pop(0) opponent_cards.append(str(o_card)) player_cards.pop(0) elif o_card == p_card: continue_playing = input("The cards are the same, time for a tie-breaker? Enter yes to continue: ") if continue_playing == "yes": print("You and the opponent place 3 cards face down and one face up. Lets see who wins the war!") p_card1 = player_cards[1] p_card2 = player_cards[2] p_card3 = player_cards[3] p_card4 = int(player_cards[4]) o_card1 = opponent_cards[1] o_card2 = opponent_cards[2] o_card3 = opponent_cards[3] o_card4 = int(opponent_cards[4]) print("You place down a ", p_card4, "and your opponent has placed down a ", o_card4) if p_card4 > o_card4: print("Congrats! You won the war and gain a ", o_card1, o_card2, o_card3, "and", o_card4) player_cards.pop(0) player_cards.pop(1) player_cards.pop(2) player_cards.pop(3) player_cards.pop(4) player_cards.append(str(p_card)) player_cards.append(str(p_card1)) player_cards.append(str(p_card2)) player_cards.append(str(p_card3)) player_cards.append(str(p_card4)) opponent_cards.pop(0) opponent_cards.pop(1) opponent_cards.pop(2) opponent_cards.pop(3) opponent_cards.pop(4) player_cards.append(str(o_card)) player_cards.append(str(o_card1)) player_cards.append(str(o_card2)) player_cards.append(str(o_card3)) player_cards.append(str(o_card4)) elif o_card4 > p_card4: print("You lost the war, your opponent gains a ", p_card1, p_card2, p_card3, "and", p_card4) opponent_cards.pop(0) opponent_cards.pop(1) opponent_cards.pop(2) opponent_cards.pop(3) opponent_cards.pop(4) opponent_cards.append(str(o_card)) opponent_cards.append(str(o_card1)) opponent_cards.append(str(o_card2)) opponent_cards.append(str(o_card3)) opponent_cards.append(str(o_card4)) player_cards.pop(0) player_cards.pop(1) player_cards.pop(2) player_cards.pop(3) player_cards.pop(4) opponent_cards.append(str(p_card)) opponent_cards.append(str(p_card1)) opponent_cards.append(str(p_card2)) opponent_cards.append(str(p_card3)) opponent_cards.append(str(p_card4)) elif o_card4 == p_card4: print("Wow, another tie! You placed a ", p_card4, "and your opponent placed a ", o_card4, ".") p_coin = input("Lets decide this one with a coin flip. Heads or tails? ") continue_playing = input("Would you like to keep playing? Enter yes to continue: ") coin = randint(1, 2) if coin == 1 and p_coin == "heads" and continue_playing == "yes": print("You won the coin flip and gain the cards!") player_cards.pop(0) player_cards.pop(1) player_cards.pop(2) player_cards.pop(3) player_cards.pop(4) player_cards.append(str(p_card)) player_cards.append(str(p_card1)) player_cards.append(str(p_card2)) player_cards.append(str(p_card3)) player_cards.append(str(p_card4)) opponent_cards.pop(0) opponent_cards.pop(1) opponent_cards.pop(2) opponent_cards.pop(3) opponent_cards.pop(4) player_cards.append(str(o_card)) player_cards.append(str(o_card1)) player_cards.append(str(o_card2)) player_cards.append(str(o_card3)) player_cards.append(str(o_card4)) elif coin == 2 and p_coin == "tails": print("You won the coin flip and gain the cards!") player_cards.pop(0) player_cards.pop(1) player_cards.pop(2) player_cards.pop(3) player_cards.pop(4) player_cards.append(str(p_card)) player_cards.append(str(p_card1)) player_cards.append(str(p_card2)) player_cards.append(str(p_card3)) player_cards.append(str(p_card4)) opponent_cards.pop(0) opponent_cards.pop(1) opponent_cards.pop(2) opponent_cards.pop(3) opponent_cards.pop(4) player_cards.append(str(o_card)) player_cards.append(str(o_card1)) player_cards.append(str(o_card2)) player_cards.append(str(o_card3)) player_cards.append(str(o_card4)) else: print("You lost the coin flip and your opponent gains the cards.") opponent_cards.pop(0) opponent_cards.pop(1) opponent_cards.pop(2) opponent_cards.pop(3) opponent_cards.pop(4) opponent_cards.append(str(o_card)) opponent_cards.append(str(o_card1)) opponent_cards.append(str(o_card2)) opponent_cards.append(str(o_card3)) opponent_cards.append(str(o_card4)) player_cards.pop(0) player_cards.pop(1) player_cards.pop(2) player_cards.pop(3) player_cards.pop(4) opponent_cards.append(str(p_card)) opponent_cards.append(str(p_card1)) opponent_cards.append(str(p_card2)) opponent_cards.append(str(p_card3)) opponent_cards.append(str(p_card4)) # This is another check to see how the content of the decks has changed during the round. print(player_cards) print(opponent_cards) p = len(player_cards) o = len(opponent_cards) if p > o: print("You have won the game!") elif o > p: print("You lost, the opponent won this game.") else: print("You and the opponent have tied.")

Rock Paper Scissors

This is a typical game of rock paper scissors coded using python.

# Rock Paper Scissors from random import randint loop = input("Do you want to play rock paper scissors? Enter yes or no: ") while loop != "no": number = randint(0, 2) plays = ["rock", "paper", "scissors"] opponent = plays[number] play = str(input("Type in either rock, paper or scissors: ")) if (play != "rock") and (play != "paper") and (play != "scissors"): print("You may have misspelled a word") elif play == opponent: print("Tie! ") elif opponent == "rock": if play == "scissors": print("You lose, rock beats scissors. ") elif play == "paper": print("You win, paper beats rock. ") elif opponent == "paper": if play == "rock": print("You lose, paper beats rock. ") elif play == "scissors": print("You win, scissors beats paper") elif opponent == "scissors": if play == "rock": print("You win, rock beats scissors") elif play == "paper": print("You lose, scissors beat paper") loop = input("Do you want to play again? Enter either yes or no: ") print("Thanks for playing!")

Hangman Game

This is a typical hangman game that is coded using python and uses turtle for the graphical aspects.

# Hangman from random import randint import turtle s = turtle.getscreen() t = turtle.Turtle() t.shapesize(1, 1, 1) t.penup() t.goto(-250, -220) t.pendown() t.goto(-190, -220) t.penup() t.goto(-220, -220) t.pendown() t.goto(-220, 220) t.goto(0, 220) t.goto(0, 170) number = randint(0, 19) words = ["tiger", "television", "cinnamon", "racetrack", "lemonade", "closet", "leopard", "smoothie", "strawberry", "snowman", "pineapple", "counter", "coyote", "sewing", "movement", "paradox", "computer", "eighteen", "musical", "fantastic"] word = words[number] length = len(word) wrong_guesses = [] x = "_" underscore_list = [] for i in range(length): underscore_list.append(x) while len(wrong_guesses) < 6 and "_" in underscore_list: letter_guess = input("Input a letter you think is in the word: ") indexes = [index for index, element in enumerate(word) if element == letter_guess] if letter_guess in word: print("Nice job, that is one of the letters in the word!") for i in range(0, len(indexes)): place = indexes[0] indexes.remove(indexes[0]) underscore_list[place] = letter_guess else: wrong_guesses.append(letter_guess) print("That letter is not in the word, keep trying :)") guesses_left = 6 - len(wrong_guesses) if len(wrong_guesses) == 1: t.penup() t.goto(0, 110) t.pendown() t.circle(30) elif len(wrong_guesses) == 2: t.goto(0, -20) elif len(wrong_guesses) == 3: t.penup() t.goto(0, 90) t.pendown() t.goto(-50, 70) elif len(wrong_guesses) == 4: t.penup() t.goto(0, 90) t.pendown() t.goto(50, 70) elif len(wrong_guesses) == 5: t.penup() t.goto(0, -20) t.pendown() t.goto(-55, -70) print("You have", guesses_left, "wrong guesses left") print("These are the correct letters in the word you have guessed so far: ", underscore_list) print("These are the letters that are not in the word:", wrong_guesses) if "_" not in underscore_list: print("Nice job, you guessed the word and won the game!") elif len(wrong_guesses) == 6: t.penup() t.goto(0, -20) t.pendown() t.goto(55, -70) t.penup() t.goto(-15, 145) t.pendown() t.goto(-10, 140) t.penup() t.goto(-10, 145) t.pendown() t.goto(-15, 140) t.penup() t.goto(15, 145) t.pendown() t.goto(10, 140) t.penup() t.goto(10, 145) t.pendown() t.goto(15, 140) print("You have no more wrong guesses left, this game is lost :(") turtle.done()

Summation Calculator

This code can add all integers, between 2 distinct integers, including negative integers, in increments of your choice, no matter which order the distinct integers are places in.

import math print("Welcome to the summation calculator") a = int(input("Please enter first number")) b = int(input("Please enter second number")) c = int(input("Please enter what increments to skip count by")) if a > b and c >= a: print("Sorry, your increment is not valid") elif b > a and c >= b: print("Sorry, your increment is not valid") elif a == b: print("Sorry, your values are equal") elif a > b: d = int(sum(range(b, a, c))) print(d) elif b > a: g = int(sum(range(a, b, c))) print(g)

2 Number Calculator

This code will allow you to use many operations with 2 numbers, not just the 4 basic operations!

print("Please insert two numbers and what you want to do with them") a = float(input("Please enter Number a here")) b = float(input("Please enter Number b here")) Operation = input("Please enter operation here. Please use the words Addition, Subtraction, Division, Multiplication, " "Square Root of a, Square Root of b, a choose b, b choose a,\n a to the power of b, and b to the" "power of a. If you don't want 2 numbers, please enter a random number in that slot. Thank you.") if Operation == "Addition": print(a+b) elif Operation == "Subtraction": print(a-b) elif Operation == "Division": print(a/b) elif Operation == "Multiplication": print(a*b) elif Operation == "a choose b": c = math.comb(int(a), int(b)) print(c) elif Operation == "b choose a": d = math.comb(int(b), int(a)) print(d) elif Operation == "a to the power of b": g = pow(int(a), int(b)) print(g) elif Operation == "b to the power of a": h = math.comb(int(b), int(a)) print(h) elif Operation == "Square root of a": j = math.sqrt(int(a)) print(j) elif Operation == "Square root of b": k = math.sqrt(int(b)) print(k) else: print("The operation given is not valid. Please try again.")

Regular Polygon and Circle Area Calculator

This will allow you to find the approximate area of several regular polygons and circles.

import math a = float(input("Please enter what regular polygon you want to find the area of. Options area a circle, equilateral " "triangle, square, pentagon, hexagon, octagon")) b = float(input("Please enter side length or radius of your polygon")) if a == "circle": print(3.1415 * b * b) elif a == "triangle": print(b * b * 0.433) elif a == "square": print(b * b) elif a == "pentagon": print(1.72 * b * b) elif a == "hexagon": print(2.598 * b * b) elif a == "octagon": print(4.828 * b * b) else: print("Sorry, either your polygon or length/radius is wrong")

Triangle Checker

This code will allow you to find if your triangle is equilateral, isosceles, scalene, acute, obtuse, or/and right!

Angle_A = float(input("Please enter value for angle 1 of a triangle")) Angle_B = float(input("Please enter value for angle 2 of b triangle")) Angle_C = float(input("Please enter value for angle 3 of c triangle")) if Angle_A + Angle_B + Angle_C != 180: print("Sorry, the angles you entered are not valid, please try again.") elif Angle_A > 90 or Angle_B > 90 or Angle_C > 90: print("Your triangle is Obtuse") elif Angle_A == 90 or Angle_B == 90 or Angle_C == 90: print("Your triangle is a Right triangle") elif Angle_A < 90 and Angle_B < 90 and Angle_C < 90: print("Your triangle is acute") elif Angle_A == Angle_B or Angle_B == Angle_C or Angle_A == Angle_C: print("Your triangle is isosceles") elif Angle_A != Angle_B != Angle_C: print("Your triangle is scalene") elif Angle_A == Angle_B == Angle_C: print("Your triangle is equilateral")

Currency Converter

This is a currency converter that includes USD, Pound, Euro, Rupee, and Yen. It was made using pyqt5.

This is a user-friendly Hangman game. I was working on it for three weeks.

https://repl.it/@BYLDOG/hangman
print("Starting a game of Hangman.") from random import randint valid1 = 0 x = 0 hg = 0 valid2 = 0 valid27000 = [ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" ] valid30 = [ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25" ] valid900 = ["3", "4", "5", "6", "7", "8", "9", "10"] allwords = [ "dog", "cat", "man", "woman", "drums", "cousin", "brother", "epidemic", "pencilcase" ] y = len(allwords) validwords = [] while valid1 == 0: attempts = input("How many incorrect attempts do you want? [1-25] ") if attempts not in valid30: print("Not a valid number from 1 to 25") else: valid1 = 1 attempts = int(attempts) while valid2 == 0: minlen = input("What's the minimum length of the word? [3-10] ") if minlen not in valid900: print("Not a valid number from 3 to 10") else: valid2 = 1 minlen = int(minlen) while x in range(-1, y - 1): x = x + 1 lenx = int(len(allwords[x])) valid3 = max(lenx, minlen) if valid3 == lenx: validwords.append(allwords[x]) wordnm = randint(0, len(validwords) - 1) word = validwords[wordnm] wordlen = len(word) guess = [] wordlist = [] for x in range(0, wordlen): x = x + 1 guess.append("*") wordlist.append(word[x - 1]) while attempts > 0: print(guess) guess1 = input("Enter your guess: ") if guess1 not in valid27000: print( "This is not a valid guess. Try inputting a lowercase English letter" ) else: if guess1 not in wordlist: if attempts != 1: print("This letter is not in the word. Try again") else: print( "This letter is not in the word. You have ran out of attempts." ) attempts = attempts - 1 else: print("This letter is in the word") while hg in range(0, len(wordlist)): if wordlist[hg] == guess1: guess[hg] = guess1 hg = hg + 1 if guess == wordlist: print("You won! Congrats. The word is " + word) while True: aohuni = 1 hg = 0

Update For Code On Web Scraper

I accidentally forgot to include a filter for prices, here's the updated code.

""" Copyright Adam Blumenfeld All rights reserved """ # These are the variable you have to set Email = "email@example.com" Password = "examplepassword" # Imports import requests from bs4 import BeautifulSoup import smtplib import time import datetime import keyboard as k import sys wait = True def wait_false(): global wait wait = False k.add_hotkey("ctrl+g", lambda: wait_false()) # URLS you want to check URLS = ["https://www.amazon.com/Lysol-Bathroom-Cleaner-Island-Breeze/dp/B06ZZQSH77/ref=sr_1_5?dchild=1&keywords=lysol+spray&qid=1588110272&sr=8-5", "https://www.amazon.com/Lysol-Disinfectant-Spray-Morning-Breeze/dp/B01IAIMYF2/ref=sr_1_1?dchild=1&keywords=lysol+disinfectant&qid=1588133936&sr=8-1", "https://www.amazon.com/Scott-67805-Recycled-Bathroom-Tissue/dp/B0040ZOIZO/ref=pd_ybh_a_5?_encoding=UTF8&psc=1&refRID=Y73XTT0K4CR1PQMFPV3V", "https://www.amazon.com/AmScope-120X-1200X-M30-ABS-KT2-W-Beginner-Microscope/dp/B00GGY85EC/ref=sr_1_1?dchild=1&keywords=microscope&qid=1588207972&s=industrial&sr=1-1"] # Time you want to space out already made emails (If you want to never relese emails on an item again, set it to float('inf')) cooldown_time = 7200 headers = { "User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.113 Safari/537.36'} def check(URL, maillist): page = requests.get(URL, headers=headers) soup1 = BeautifulSoup(page.content, 'html.parser') soup = BeautifulSoup(soup1.prettify(), "html.parser") title = soup.find(id="productTitle").get_text().strip().split(',')[0] available = soup.find(id="availability") price = soup.find(id="priceblock_ourprice") if price != None: print("Product is available") send_mail(title, URL, maillist) return True if available == None: print("Product is available") send_mail(title, URL) return True available = available.findChild('span').get_text().strip()[0:15] if available == "Temporarily out": print("Product is available") send_mail(title, URL, maillist) return True print("Product isn't available") return False def send_mail(title, link, maillist): global email global password server = smtplib.SMTP('smtp.gmail.com', 587) server.ehlo() server.starttls() server.ehlo() server.login(email, password) subject = f'"{title}" is available!' body = f'Check the Amazon link to see availablility: {link}' msg = f"Subject: {subject}\n\n{body}" server.sendmail( email, maillist, msg ) print('Email Has Been Sent!') server.quit() wait = True cooldown = {} # The time you want between checks time_between_checks = 120 while True: print("Press CTRL+g to fast forward check") i = 0 while i < time_between_checks and wait: time.sleep(1) print("Time since last check:", i, "\\", time_between_checks, end="\r") i += 1 wait = True print("\n") for URL in URLS: time_ = datetime.datetime.now() print(f"Checking... <{time_}> <{URL}>\n") if cooldown.get(URL) != None: if time.time() - cooldown[URL] >= cooldown_time: del cooldown[URL] else: print(f"Cooldown time for URL <{URL}>: {cooldown_time-int((time.time() - cooldown[URL]) % 60)} seconds") continue availability = check(URL, sys.argv) if availability: cooldown[URL] = time.time() print("\n\n")

Web Scraper For Amazon Availibility

This web scraper checks amazon links by URL every two minutes, and emails you when those products are available. There is a cooldown of 4 hours for products that have been found available and emailed to you, but this cooldown only affects the particular item and not all of the URLs. By the way these parameters are completely customizable (you can have your wait time be 5 minutes, your cooldown be infinite, etc.) I made this scraper to help people out with panic buying and the lowered availability of basic items. In my original program, I made an email called amazonbot100@gmail.com to carry out the emails. To set up an email with this program, here are the steps: 1. Create a new email (Recommended, but not required) 2. Enable two-factor authentication for your account (This is required for the next step) 3. Set up App Passwords for your account and create a new one for your computer. 4. Paste in the email address to the Email variable at the top, and paste the app password into the Password variable under that. 4.5. Search up "my user agent" on google and paste it into the user agent 5. Run python -m pip install bs4 6. Run python -m pip install requests 7. Run python -m pip install keyboard Also, I understand that the code isn't the most efficient, especially towards the end, though I was in a rush so don't judge me xD. Usage: python scraper.py email-to-send-1@example.com email-to-send-2@example.com email-to-send-3@example.com email-to-send-you-get-the-point@example.com

""" Copyright Adam Blumenfeld All rights reserved """ # These are the variable you have to set Email = "email@example.com" Password = "examplepassword" # Imports import requests from bs4 import BeautifulSoup import smtplib import time import datetime import keyboard as k import sys wait = True def wait_false(): global wait wait = False k.add_hotkey("ctrl+g", lambda: wait_false()) # URLS you want to check URLS = ["https://www.amazon.com/Lysol-Bathroom-Cleaner-Island-Breeze/dp/B06ZZQSH77/ref=sr_1_5?dchild=1&keywords=lysol+spray&qid=1588110272&sr=8-5", "https://www.amazon.com/Lysol-Disinfectant-Spray-Morning-Breeze/dp/B01IAIMYF2/ref=sr_1_1?dchild=1&keywords=lysol+disinfectant&qid=1588133936&sr=8-1", "https://www.amazon.com/Scott-67805-Recycled-Bathroom-Tissue/dp/B0040ZOIZO/ref=pd_ybh_a_5?_encoding=UTF8&psc=1&refRID=Y73XTT0K4CR1PQMFPV3V", "https://www.amazon.com/AmScope-120X-1200X-M30-ABS-KT2-W-Beginner-Microscope/dp/B00GGY85EC/ref=sr_1_1?dchild=1&keywords=microscope&qid=1588207972&s=industrial&sr=1-1"] # Time you want to space out already made emails (If you want to never relese emails on an item again, set it to float('inf')) cooldown_time = 7200 headers = { "User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.113 Safari/537.36'} def check(URL, maillist): page = requests.get(URL, headers=headers) soup1 = BeautifulSoup(page.content, 'html.parser') soup = BeautifulSoup(soup1.prettify(), "html.parser") title = soup.find(id="productTitle").get_text().strip().split(',')[0] available = soup.find(id="availability") if available == None: print("Product is available") send_mail(title, URL) return True available = available.findChild('span').get_text().strip()[0:15] if available == "Temporarily out": print("Product is available") send_mail(title, URL, maillist) return True print("Product isn't available") return False def send_mail(title, link, maillist): global email global password server = smtplib.SMTP('smtp.gmail.com', 587) server.ehlo() server.starttls() server.ehlo() server.login(email, password) subject = f'"{title}" is available!' body = f'Check the Amazon link to see availablility: {link}' msg = f"Subject: {subject}\n\n{body}" server.sendmail( email, maillist, msg ) print('Email Has Been Sent!') server.quit() wait = True cooldown = {} # The time you want between checks time_between_checks = 120 while True: print("Press CTRL+g to fast forward check") i = 0 while i < time_between_checks and wait: time.sleep(1) print("Time since last check:", i, "\\", time_between_checks, end="\r") i += 1 wait = True print("\n") for URL in URLS: time_ = datetime.datetime.now() print(f"Checking... <{time_}> <{URL}>\n") if cooldown.get(URL) != None: if time.time() - cooldown[URL] >= cooldown_time: del cooldown[URL] else: print(f"Cooldown time for URL <{URL}>: {cooldown_time-int((time.time() - cooldown[URL]) % 60)} seconds") continue availability = check(URL, sys.argv) if availability: cooldown[URL] = time.time() print("\n\n")

Simple Imperial to Metric Converter//Temperature

This converter is written on Python and with it, you can convert any Fahrenheit measurement to Celsius.

https://repl.it/@BYLDOG/OldfashionedAquaOpen64
fdegrees=int(input("Enter the value in degrees Farenheit: ")) cdegrees1=fdegrees-32 cdegrees=cdegrees1/1.8 print("Your value in degrees Celsius is "+str(cdegrees))
1 2 ... 5