Geometric Progression

This python program asks the user to input the number of characters they want to use in a list. The user then inputs multiple numbers to form their list. The program runs through these numbers and checks if their list forms a geometric progression. If this sequence creates a geometric progression, the ratio of that progression is shown as well.

firstlist = [] # The list with the inputted numbers. secondlist = [] # The list with the division between each number. length = int(input("How many numbers do you want in the list? ")) # Ask user how many numbers in sequence. # The user inputs a number and that number is added to the firstlist def inputlist (length): for x in range(0, length): number = float(input("Type your number: ")) firstlist.append(number) division = 0 # Every two numbers in firstlist are divided, and the divided number is added to secondlist. def divlist (length): for y in range(0, length): if y < (len(firstlist)-1): division = (firstlist[y + 1] / firstlist[y]) secondlist.append(division) inputlist(length) divlist(length) counter = 0 # Counter to count the number of times the ratio is equal to each other. firstnum = secondlist[0] # The list of all numbers from secondlist are compared to each other to see if they are similar or not. def geometric (secondlist, firstnum, counter): for x in secondlist: if firstnum == x: # This if-statement is to start the counter with the base of 1. firstnum == x counter = counter + 1 if counter == len(secondlist): # If the progressed counter is equal to the number of numbers in the list, then geometric progression exists. print("This sequence is a geometric progression. The common ratio is", firstnum) if x == secondlist[len(secondlist)-1] and counter != len(secondlist): # If x is equal to the last number in the division list (to make sure the list is ran through) and the counter isn't equal to the number of characters in the list, a geometric progression does not exist. print("This is not a geometric progression.") geometric(secondlist, firstnum, counter)

Correlation

import math SPY = [170.66, 170.95, 170.70, 169.73, 169.18, 169.80, 169.31, 169.11, 169.61, 168.74, 166.38, 165.83] JPM = [56.54, 56.40, 56.10, 55.49, 55.30, 54.83, 54.52, 54.09, 54.29, 54.15, 53.29, 51.83] SPY2 = [] JPM2 = [] SPY_JPM = [] digit1 = 0 digit2 = 0 digit3 = 0 digit4 = 0 digit5 = 0 digit6 = 0 digit7 = 0 #1. First, every period needs to be squared for both securities. for x in range(0, len(SPY), 1): digit = SPY[x] digit = digit * digit #print(digit) SPY2.append(digit) for x in range(0, len(JPM), 1): digit = JPM[x] digit = digit * digit #print(digit) JPM2.append(digit) #2. Multiply the each period value of SPY by each period of JPM. for x in range(0, len(JPM), 1): digit = JPM[x] * SPY[x] #print(digit) SPY_JPM.append(digit) #3. Find the Average Value for each column. SPY_AVG = sum(SPY)/len(SPY) #print(SPY_AVG) JPM_AVG = sum(JPM)/len(JPM) #print(JPM_AVG) SPY2_AVG = sum(SPY2)/len(SPY2) #print(SPY2_AVG) JPM2_AVG = sum(JPM2)/len(JPM2) #print(JPM2_AVG) SPY_JPM_AVG = sum(SPY_JPM)/len(SPY_JPM) #print(SPY_JPM_AVG) #Variance SPY_Variance = SPY2_AVG - (SPY_AVG * SPY_AVG) #print(SPY_Variance) JPM_Variance = JPM2_AVG - (JPM_AVG * JPM_AVG) #print(JPM_Variance) #Covariance covariance = SPY_JPM_AVG - (SPY_AVG * JPM_AVG) #print(covariance) #CorrelationCoefficient correlationCoefficient = covariance/math.sqrt(SPY_Variance * JPM_Variance) print(correlationCoefficient)

DNA to RNA

DNA = [] aminoAcids = "" from random import randint word = "ACTGY" randomVal = randint(0,3) x = word[randomVal] for i in range(1,16): DNA.append(word[randint(0,3)]) res = [sub.replace('A', 'U') for sub in DNA] DNA = res res = [sub.replace('T', 'A') for sub in DNA] DNA = res res = [sub.replace('C', 'X') for sub in DNA] DNA = res res = [sub.replace('G', 'C') for sub in DNA] DNA = res res = [sub.replace('X', 'G') for sub in DNA] DNA = res print(DNA) print(str(DNA)) listToStr = ''.join(map(str, DNA)) print(listToStr) aminoAcidMap = ['A', 'A', 'A', 'A', 'C', 'C', 'D', 'D', 'E', 'E', 'F', 'F', 'G', 'G', 'G', 'G', 'H', 'H', 'I', 'I', 'I', 'K', 'K', 'L', 'L', 'L', 'L', 'L', 'L', 'M', 'N', 'N', 'P', 'P', 'P', 'P', 'Q', 'Q', 'R', 'R', 'R', 'R', 'R', 'R', 'S', 'S', 'S', 'S', 'S', 'S', 'T', 'T', 'T', 'T', 'V', 'V', 'V', 'V', 'W', 'Y', 'Y'] RNACombo = ["GCA" ,"GCC" ,"GCU" ,"GCG" ,"UGC" ,"UGU","GAC" ,"GAU","GAG" ,"GAA","UUC" ,"UUU","GGA" ,"GGG" ,"GGC" ,"GGU","CAC" ,"CAU""AUA" ,"AUC" ,"AUU" ,"AAA" ,"AAG","UUG" ,"UUA" ,"CUA" ,"CUC" ,"CUU" ,"CUG","AUG","AAC" ,"AAU","CCC" ,"CCA" ,"CCU" ,"CCG","CAA" ,"CAG" ,"AGA" ,"AGG" ,"CGA" ,"CGC" ,"CGG" ,"CGU","AGC" ,"AGU" ,"UCA" ,"UCC" ,"UCG" ,"UCU" ,"ACA" ,"ACC" ,"ACG" ,"ACU","GUA" ,"GUC" ,"GUG" ,"GUU","UGG","UAC" ,"UAU"] for i in range(0,15,3): x = listToStr[i:i+3] print(x) MatchFound = False for y in RNACombo: if y == x: z = RNACombo.index(y) aminoAcids = aminoAcids + aminoAcidMap[z] MatchFound = True break if MatchFound == False: print("STOP!") if MatchFound == False: print("aminoAcids:" + aminoAcids + "False") print("aminoAcids:" + aminoAcids)

Set 2 exercise for python 1A

#1)Create a for loop from 1 to 1000, printing every 3rd number. for m in range(30,350,2): print(m) #2)Create a for loop from 30 to 350 printing every even number. for z in range(30,350,2): print(z) #3)Create a for loop from 200 to -200 printing multiples of 3. for x in range(-200,200,3): if x&3 == 0: print(x) #4)Create a for loop from 1 to 1000, printing only multiples of 7. for i in range(1,1000,1): if i&7 == 0: print(i) #5)Create a program which will ask for your recent exam score out of 120 and tell you what grade you got and how many more points you would have needed to get the next grade up. A - 90% and above, B- 80% to 89.9%, C- 70% to 79.99% Student_grade = int(input("What was your test score out of 120: ")) if Student_grade >= 108: print("You got the highest score! You got an A.") elif Student_grade >= 96 and Student_grade <= 108: Points_needed_1 = 108 - Student_grade print("You got a B.You needed " + str(Points_needed_1) + " point(s) to get an A.") elif Student_grade >= 84 and Student_grade <= 96: Points_needed = 96 - Student_grade print("You got a C.You needed " + str(Points_needed) + " point(s) to get an B.") #6)Ask the user to input their favorite basketball team. Print out whether it is in the Eastern or Western Conference. Warriors- Western, Lakers - Western, Celtics - Eastern, Cavaliers - Eastern fav_basketball_team = input("What is your favorite team in the NBA?") east = ['Milwaukee Bucks', 'Toronto Raptors', 'Boston Celtics', 'Miami Heat', 'Indiana Pacers', 'Philadelphia 76ers', 'Brooklyn Nets', 'Orlando Magic', 'Washington Wizards', 'Charlotte Hornets', 'Chicago Bulls', 'New York Knicks', 'Detroit Pistons', 'Atlanta Hawks', 'Cleveland Cavaliers'] west = ['Los Angeles Lakers', 'LA Clippers', 'Denver Nuggets', 'Utah Jazz', 'Oklahoma City Thunder', 'Houston Rockets', 'Dallas Mavericks', 'Memphis Grizzlies', 'Portland Trail Blazers', 'New Orleans Pelicans', 'Sacramento Kings', 'San Antonio Spurs', 'Phoenix Suns', 'Minnesota Timberwolves', 'Golden State Warriors'] if west.count(fav_basketball_team) > 0 : print("Your favorite team is in the Western conference") elif east.count(fav_basketball_team) > 0 : print("Your favorite team is in the Eastern conference") #7)Create a program which asks the user for 3 numbers representing the year, month and day e.g 1982 10 08 and then outputs in the form 8th October 1982. month = input("What month is it: ") year = input("What year is it: ") day = input("What number day in the month is it: ") day = int(day) if day <= 20: print(str(day) + 'th' + ' ' + str(month) + ' ' + str(year)) if day > 20 and day <= 31: print(str(day) + '' + ' ' + str(month) + ' ' + str(year)) #12)Create a for loop that prints all numbers from 1 to 80 except ones that are multiples of 6. for a in range(1,80,1): if i&7 == 0: print(i) #13)Create a for loop that only prints numbers from 1 to 40 that are multiples of 4. for p in range(1,40,1): if p&4 != 0: print(p) #14)Ask the user to input a number. If the number is between 0 and 9, print "Single digit". If the number is between 10 and 99, print "Double Digit". Otherwise, print "Something else" num = input("enter a number:") num = int(num) if num >= 0 or num <= 9: print("single digit") elif num >=10 or num <= 99: print("double digit") else: print("something else") #15)Ask the user to input a word. Print out whether or not it is a palindrome. my_str = input("Choose a word") my_str = my_str.casefold() rev_str = reversed(my_str) if list(my_str) == list(rev_str): print("The string is a palindrome.") else: print("The string is not a palindrome.")

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))

Classroom Attendance

This program asks you the attendance of six of your students, and it gives a ratio of the number of number of students present.

Simple Metric to Imperial Converter//Weight

This converter is written on Python and with it, you can convert any metric measurement to pounds or ounces.

https://repl.it/@BYLDOG/RigidUnrealisticMacro
amount=int(input("How many? ")) msrmnt=input("What measurement(kg or g)? ") cvt=input("Convert to what(lb or oz)? ") if msrmnt=="kg": if cvt=="lb": print(amount*2.2) if cvt=="oz": print(amount*35.3) if msrmnt=="g": if cvt=="lb": print(amount/454) if cvt=="oz": print(amount/28)

DNA Converter

This is a program that converts the DNA to RNA, amino acid, and protein. It asks the user for its DNA.

Guessing Game

The goal of this game is to guess the number chosen by the CPU between 1-100 in at most 5 tries, along with hints for help.

1 2 ... 28