Atbash Cipher

The At--bash cipher is an encryption method in which each letter of a word is replaced with its "mirror" letter in the alphabet: A <=> Z; B <=> Y; C <=> X; etc. This function applies the atbash cipher to any string that is inputted.

#Making a list of all the possible letters- uppercase and lowercase. I also added special characters just in case people want to type them. But they will be the same after ciphering string2= "zZyYxXwWvVuUtTsSrRqQpPoOnNmMlLkKjJiIhHgGfFeEdDcCbBaA !,./';:[]()+=-" string= "aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ !,./';:[]()+=-" alphabet= list(string) printlist= "" reversealpha= list(string2) returnlist= [] #The input statement asks the user to input a string to be ciphered word= input("Input a string. ") #The Atbash cipher is applied def atbash(word): #Converting the string into a list so I can loop through it letters= list(word) for x in letters: # Finding the index of a letter in the alphabet and then finding the letter with the same index in the reverse alphabet a= alphabet.index(x) y= reversealpha[a] returnlist.append(y) return returnlist h=(atbash(word)) #Converting the list into a string print(printlist.join(h))

Rock, Paper, Scissors!

This is my version of Rock, Paper, Scissors. If you choose "Rock", type R,r,Rock, or rock. If you choose "Paper", type P,p,Paper, or paper. If you choose "Scissors", type S,s,Scissors, or scissors. If you see (y/n) Y stands for Yes and N stands for no.

import random comp_wins = 0 player_wins = 0 def Choose_Option(): user_choice = input("Choose Rock, Paper or Scissors: ") if user_choice in ["Rock", "rock", "r", "R"]: user_choice = "r" elif user_choice in ["Paper", "paper", "p", "P"]: user_choice = "p" elif user_choice in ["Scissors", "scissors", "s", "S"]: user_choice = "s" else: print("I don't understand, try again.") Choose_Option() return user_choice def Computer_Option(): comp_choice = random.randint(1, 3) if comp_choice == 1: comp_choice = "r" elif comp_choice == 2: comp_choice = "p" else: comp_choice = "s" return comp_choice while True: print("") user_choice = Choose_Option() comp_choice = Computer_Option() print("") if user_choice == "r": if comp_choice == "r": print("You chose rock. The computer chose rock. You tied.") elif comp_choice == "p": print("You chose rock. The computer chose paper. You lose.") comp_wins += 1 elif comp_choice == "s": print("You chose rock. The computer chose scissors. You win.") player_wins += 1 elif user_choice == "p": if comp_choice == "r": print("You chose paper. The computer chose rock. You win.") player_wins += 1 elif comp_choice == "p": print("You chose paper. The computer chose paper. You tied.") elif comp_choice == "s": print("You chose paper. The computer chose scissors. You lose.") comp_wins += 1 elif user_choice == "s": if comp_choice == "r": print("You chose scissors. The computer chose rock. You lose.") comp_wins += 1 elif comp_choice == "p": print("You chose scissors. The computer chose paper. You win.") player_wins += 1 elif comp_choice == "s": print("You chose scissors. The computer chose scissors. You tied.") print("") print("Player wins: " + str(player_wins)) print("Computer wins: " + str(comp_wins)) print("") user_choice = input("Do you want to play again? (y/n)") if user_choice in ["Y", "y", "yes", "Yes"]: pass elif user_choice in ["N", "n", "no", "No"]: break else: break

Restaurant Management system

Pyqt5 gui restaurant management system. Use "publicacount" for username and "secretpassword" for password.

Python Mega Program

This program is a bunch of programs that I have written throughout this class combined into one big program. This includes things like a prime or composite program, a calendar program, and many more!

def PrimeNumbers(): Input = int(input ("Enter a number: ")) isPrime = True if Input =="2": print ("2 is prime!") elif Input % 2 == 0: print (str(Input) + " is composite!") isPrime = False else: for i in range (3,int(Input/2),2): if (Input % i) == 0: print (str(Input) + " is composite!") print(i) isPrime = False break if isPrime != False: print (str(Input) + " is prime!") #This program determines if a number is prime or composite by checking if the number is even or odd, if its even its automatically determined as compostie. If the number is odd the porgram runs a simple algorithm to see if any other numbers multiply into it. If the number still doesn't meet any of these criteria then it is detrmined as prime. def MilestoKilometres(): Miles = int(input("How many miles? ")) Kilometres = Miles * 1.60934 print (str(Kilometres) + " Kilometres") #This program simply converts miles to kilometres by multiplying by the conversion factor. def KilometrestoMiles(): Kilometres = int(input("How many kilometres? ")) Miles = Kilometres / 1.60934 print (str(Miles) + " Miles") #This program simply converts kilometres to miles by dividing by the conversion factor. def CalendarYear(): year = int(input("Which year? ")) import calendar print (calendar.calendar(year, 2, 1, 6)) #This program prints the calendar for an entrie given year using the calendar function. def CalendarMonth(): year = int(input("Which year? ")) month = int(input("Which month? (Enter the number of the month) ")) import calendar print (calendar.month(year, month)) #This program prints the calendar for an entrie given month using the calendar function. NumberList = [] def Multiply2Numbers(): Number1 = int(input("Enter the first number? " )) Number2 = int(input("Enter the second number? " )) Solution = Number1 * Number2 print (str(Number1) + " * " + str(Number2) + " = " + str(Solution)) #This program just multiples 2 numbers. def MultTable(): Amount = int(input("How many tables do you want to print? ")) for x in range (0,Amount): Numbers = int(input("Which number's tables do you want to print? ")) NumberList.append(Numbers) for x in (NumberList): for y in range (1,11): Answer = x * y print (x , "times" , y , "=" , Answer) #This program prints the multiplication tables of a given set of numbers at once. It does this through a "for loop" inside a "for loop". while True: Question = input("Hi! Which program would you like to use? Type list for a list for a list of programs. ") if Question == "list": print ("Write Write 'MtoK' or 'KtoM' for miles and kilometers conversion. Write 'P or C' for prime or composite. Write 'month' or 'year' for the calendar for one month or the whole year. Write 'table' or 'mulitply' for multiplying 2 numbers or creating a multiplication table. ") if Question == "MtoK": MilestoKilometres() if Question == "KtoM": KilometrestoMiles() if Question == "P or C": PrimeNumbers() if Question == "month": CalendarMonth() if Question == "year": CalendarYear() if Question == "table": MultTable() if Question == "multiply": Multiply2Numbers() #This part of the program allows for the user to select which program they would like to use by using if statements and gives them the option to print a list of all the possible programs as well.
A Nov 16

Cool bro

Number Guessing Game

import random #while flag = True while flag: num = input("Type a number for an upper bound: ") if num.isdigit(): print("Let's Play!") num = int(num) flag = False: else: print("Invalid input! Try Again!") secret = random.randint(1,num) guess = 5 count = 1 while guess != secret: guess = input("Type a number between 1 and ' + str (num) + ": ") if guess.isdigit(): guess = int(guess) if guess == secret: print("You got it!") else: print("Try agian!") count += 1 print('It took you', count, 'guesses!')

Hangman game

from random import randint import time numberofplayers= input("Do you want to play with 1 or 2 players? ") #allows 2 players to play while numberofplayers != "1" and numberofplayers !="2": numerbofplayers=input("Please enter 1 or 2. Do you want to play with 1 or 2 players? ") if numberofplayers == "1": computerwords =["mouse", "mask", "car", "hat", "bottle", "flag", "poison", "curtain", "muscle", "bubble","canvas","donkey", "snow","python"] # randomly picking the word from the list pickword= computerwords[randint(0,13)] wordletters= list(pickword) wordletterscheck= list(pickword) wordlettersremove= list(pickword) allletters= ["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"] Flag= False i= 0 print("Picking a word.....") time.sleep(2) print("Your word has", len(wordletters), "letters in it.") #Choosing the number of guesses numguesses= int(input("How many guesses do you want? Please enter a number between 5 and 15. ")) while numguesses not in range (5, 16): numguesses= int(input("Please enter a number between 5 and 15. ")) #Gameplay while Flag== False: userguess= input("Please guess a lowercase letter. ") while userguess not in allletters: userguess= input("That is not a valid letter. You may have already guessed that letter. Please guess another one.") if userguess in wordletters: i=wordletters.index(userguess) print("The position of your letter in the word was", i+1) wordlettersremove.remove(userguess) allletters.remove(userguess) # If the letter is repeated in the word if userguess in wordlettersremove: if wordletterscheck.index(userguess)>= i: print("The position of your letter in the word is also", wordlettersremove.index(userguess)+2) wordlettersremove.remove(userguess) elif wordletterscheck.index(userguess) < i: print("The position of your letter in the word is also", wordlettersremove.index(userguess)+2) wordlettersremove.remove(userguess) # If the user guesses incorrectly elif userguess not in wordletters: numguesses= numguesses-1 print("The letter is not in the word. You have", numguesses, "guesses left. Please try again. ") #If the user guesses all the letters if len(wordlettersremove)== 0: Flag= True print ("You win!") # If the user runs out of guesses elif numguesses == 0: Flag= True print("Sorry. You lost the game.") elif numberofplayers == "2": userBwordchoice= input("Please enter the word you want your partner to guess. ") wordletters= list(userBwordchoice) wordletterscheck= list(userBwordchoice) wordlettersremove= list(userBwordchoice) allletters= ["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"] Flag= False i= 0 print("Your word has", len(wordletters), "letters in it.") numguesses= int(input("How many guesses do you want? Please enter a number between 5 and 15. ")) while numguesses not in range (5, 16): print("Please enter a number between 5 and 15. ") while Flag== False: userguess= input("Please guess a lowercase letter. ") while userguess not in allletters: userguess= input("That is not a valid letter. You may have already guessed that letter. Please guess another one.") if userguess in wordletters: i=wordletters.index(userguess) print("The position of your letter in the word was", i+1) wordlettersremove.remove(userguess) allletters.remove(userguess) if userguess in wordlettersremove: if wordletterscheck.index(userguess)>= i: print("The position of your letter in the word is also", wordletterscheck.index(userguess)+2) wordlettersremove.remove(userguess) elif wordletterscheck.index(userguess) < i: print("The position of your letter in the word is also", wordletterscheck.index(userguess)+2) wordlettersremove.remove(userguess) elif userguess not in wordletters: numguesses= numguesses-1 print("The letter is not in the word. You have", numguesses, "guesses left. Please try again. ") if len(wordlettersremove)== 0: Flag= True print ("You win!") elif numguesses == 0: Flag= True print("Sorry. You lost the game.")

Python Level 1A: Set 7 Exercises - #7 using locals

print("please input numbers as prompted below: ") num = int(input("Enter a number of entries: ")) vals = [] n = 0 while n < num: print("Please type the number: ", n ," entry = ", end= '') locals()["val" + str(n)] = input() print(locals()["val" + str(n)]) n +=1 for z in range(n): vals.append(locals()["val" + str(z)]) print(vals) for x in range(n): #m = x + 1 #print(vals) for y in range(x,n): print(str(vals[x]) + " * " + str(vals[0]) + " = " + str(int(vals[x]) * int(vals[0]))) #print(str(vals[y])) print(y) #print(str(vals[x]) + " * " + str(vals[x]) + " = " + str(int(vals[x]) * int(vals[y]))) print(n)

Computing N choose R using Python

Hi! This program calculates the number of ways possible to choose r items out of n items. I am still working on the program and am exploring more efficient ways to compute it because the computer cannot handle multiplication and division to a really high extent. I hope you like it!

n= int(input(("How many items are available to choose out of? "))) r= int(input("How many items do you want to choose? ")) # nCr = (N!)/ r!(n-r)! nfacbyrfac = 1 for x in range(r, n+1, 1): nfacbyrfac= nfacbyrfac*x nminusrfactorial= 1 for z in range(1,(n-r)+1,1): nminusrfactorial= nminusrfactorial* z nCr= (nfacbyrfac)/ (nminusrfactorial) print (nCr)

Function compilation

#In this program I have compiled some functions and let the user choose which one #they want to use. The aproach that I took when solving this problem is instead of #defining the functions first made it so that only the chosen function is defined # and the others are defined once the user chooses them. #Prithvi #In this program instead of defining all of the functions and then giving the commands, I programmed it so each function is only defined after I choose it while True: #Here I made it so that all of the functions would be put inside a loop so if 1 ended it would ask you the question again The_Question = input("what function would you like me to run?") if The_Question == "prime": def prime(): number = int(input("Enter The Number")) # In my primecomposite program I made it so that it was in an infinite loop so that once it ended t would break into the infinite loop again if number > 1: for i in range(2,int(number/2)): if (number % i == 0): print(number, "is not a Prime Number") break else: print(number,"is a Prime number") #I added the question to stop and try another function to make the program easier to make it more user friendly VB = input(" would you like to continue?") if VB == "yes": prime() else: return prime() if The_Question == "calendar": import calendar while 8==8: # by saying "while 8==8" I am creating an infinite loop #The print_month function is only defined b = (input("would you like to print out the calendar for a month or a year month/year ")) def print_month(): c = int(input("What year would you like the month to be from. ex. 2020 ")) d = int(input("What month would you like to be printed 1 for january, 2 for febuary etc.. ")) print (calendar.month(c,d)) VB2 = input("would you like to continue") if VB2 == "yes": print_month() else: return def print_year(): e = int(input("Which year would you like the calendar be printed of 2015, 2019 etc ")) for i in range(1,13): print (calendar.month (e,i)) if b == "month": print_month() if b == "year": print_year() if The_Question == "miles and kilometers": f = input("Would you like to convert from kiliometer to mile or from mile to kilometer mtk/ktm? ") if f == "mtk": miles_question = int(input("How many miles would you like to convert? ")) if f == "ktm": kilometer_question = int(input("How many miles would you like to convert? ")) def mtk(): res1 = miles_question * 1.608 print(res1,"kilometers") def ktm(): res2 = kilometer_question * 0.621 print(res2,"miles") if f == "mtk": mtk() if f == "ktm": ktm() g = input("would you like to make another conversion? ") if g == "yes": 0+0 if g == "no": break # If the user answers with multiplication that he/she would then need to say if they want a table or just want to multiply 2 numbers. if The_Question =="multiplication": MYlist = [] h = (input("would you like to show the multiplication table or would you like to multiply two numbers? table/two_numbers")) if h == "table": j = int(input("how many multiplication tables would you like answer 1-10")) for i in range (0, j): k = int(input("what multiplication tables do you want 1,2,3 ect.")) MYlist.append(k) # Once the user is done inputing all of the data, the program appends it all into a list which is needed in the table function def multtable(): for x in MYlist: for y in range (1,11): result = x * y print(x,"x", y, "=", result) multtable() if h == "two_numbers": def two_numbermultiply(): val3 = val1 * val2 print(val1, " x ", val2," = ", val3) val1 = int(input("input a number to be multiplied")) val2 = int(input("input a second number")) two_numbermultiply()

Function compilation

#In this program I have compiled some functions and let the user choose which one #they want to use. The aproach that I took when solving this problem is instead of #defining the functions first made it so that only the chosen function is defined # and the others are defined once the user chooses them. #Prithvi #In this program instead of defining all of the functions and then giving the commands, I programmed it so each function is only defined after I choose it while True: #Here I made it so that all of the functions would be put inside a loop so if 1 ended it would ask you the question again The_Question = input("what function would you like me to run?") if The_Question == "prime": def prime(): number = int(input("Enter The Number")) # In my primecomposite program I made it so that it was in an infinite loop so that once it ended t would break into the infinite loop again if number > 1: for i in range(2,int(number/2)): if (number % i == 0): print(number, "is not a Prime Number") break else: print(number,"is a Prime number") #I added the question to stop and try another function to make the program easier to make it more user friendly VB = input(" would you like to continue?") if VB == "yes": prime() else: return prime() if The_Question == "calendar": import calendar while 8==8: # by saying "while 8==8" I am creating an infinite loop #The print_month function is only defined b = (input("would you like to print out the calendar for a month or a year month/year ")) def print_month(): c = int(input("What year would you like the month to be from. ex. 2020 ")) d = int(input("What month would you like to be printed 1 for january, 2 for febuary etc.. ")) print (calendar.month(c,d)) VB2 = input("would you like to continue") if VB2 == "yes": print_month() else: return def print_year(): e = int(input("Which year would you like the calendar be printed of 2015, 2019 etc ")) for i in range(1,13): print (calendar.month (e,i)) if b == "month": print_month() if b == "year": print_year() if The_Question == "miles and kilometers": f = input("Would you like to convert from kiliometer to mile or from mile to kilometer mtk/ktm? ") if f == "mtk": miles_question = int(input("How many miles would you like to convert? ")) if f == "ktm": kilometer_question = int(input("How many miles would you like to convert? ")) def mtk(): res1 = miles_question * 1.608 print(res1,"kilometers") def ktm(): res2 = kilometer_question * 0.621 print(res2,"miles") if f == "mtk": mtk() if f == "ktm": ktm() g = input("would you like to make another conversion? ") if g == "yes": 0+0 if g == "no": break # If the user answers with multiplication that he/she would then need to say if they want a table or just want to multiply 2 numbers. if The_Question =="multiplication": MYlist = [] h = (input("would you like to show the multiplication table or would you like to multiply two numbers? table/two_numbers")) if h == "table": j = int(input("how many multiplication tables would you like answer 1-10")) for i in range (0, j): k = int(input("what multiplication tables do you want 1,2,3 ect.")) MYlist.append(k) # Once the user is done inputing all of the data, the program appends it all into a list which is needed in the table function def multtable(): for x in MYlist: for y in range (1,11): result = x * y print(x,"x", y, "=", result) multtable() if h == "two_numbers": def two_numbermultiply(): val3 = val1 * val2 print(val1, " x ", val2," = ", val3) val1 = int(input("input a number to be multiplied")) val2 = int(input("input a second number")) two_numbermultiply()

Python version of Blackjack

Hi! This is my attempt at making a Python version of the card game Blackjack. The program is at a rudimentary stage and is a work in progress. I am still adding to it since it lacks some of the nuances of Blackjack. I hope you enjoy it!

from random import randint # A list with the different cards gamecards= [2, 3, 4, 5, 6, 7, 8, 9, 10, "Jack", "Queen", "King", "Ace"] # Defining different lists for the dealers's cards and the player's cards dealercards=[] playercards=[] # The dealer automatically get two cards in the beginning of the game while len(dealercards)< 2: x= randint(0,12) cardchosen= gamecards[x] if cardchosen == "Jack" or cardchosen =="Queen" or cardchosen == "King": dealercards.append(10) elif cardchosen== "Ace": dealercards.append(1) else: dealercards.append(cardchosen) print ("The dealer has a down facing card and", dealercards[1]) # The player automatically gets two cards in the beginning of the game while len(playercards)< 2: x= randint(0,12) playercardchosen= gamecards[x] if playercardchosen == "Jack" or playercardchosen=="Queen" or playercardchosen == "King": playercards.append(10) elif playercardchosen == "Ace": playercards.append(1) else: playercards.append(playercardchosen) if len(playercards) == 2: print ("Your cards are", playercards[0], "and", playercardchosen) Flag= False #Gameplay for the player while sum(playercards) < 21 and Flag == False: player_action= input("Do you want to hit or stay? ") if player_action == "stay" or player_action =="Stay": Flag= True elif player_action == "hit" or player_action =="Hit": y= randint(0,12) playercardchosen= gamecards[y] if playercardchosen == "Jack" or playercardchosen == "Queen" or playercardchosen == "King": playercards.append(10) print ("You got a", playercardchosen, "and your total now is", sum(playercards)) elif playercardchosen == "Ace": playercards.append(1) print ("You got a", playercardchosen, "and your total now is", sum(playercards)) else: playercards.append(playercardchosen) print ("You got a", playercardchosen, "and your total now is", sum(playercards)) #Finding what the dealer's total is while sum(dealercards)< 17: x= randint(0,12) cardchosen= gamecards[x] if cardchosen == "Jack" or cardchosen == "Queen" or cardchosen == "King": dealercards.append(10) print("The dealer's first card was", dealercards[0]) print ("The dealer got a", cardchosen, "and his total now is", sum(dealercards)) elif cardchosen == "Ace": dealercards.append(1) print (cardchosen) else :dealercards.append(cardchosen) print ("Your total is", sum(playercards), "and your cards are", playercards) print ("The dealer has ", dealercards, "and the total is", sum(dealercards)) if sum(dealercards) > 21 and sum(playercards) > 21: print ("It is a tie!") elif sum(dealercards) < 21 and sum(dealercards) > sum(playercards): print("The dealer wins!") elif sum(playercards) < 21 and sum (playercards) > sum(dealercards): print ("You win!") elif sum(playercards) > 21: print ("The dealer wins") elif sum(dealercards) > 21: print ("You win") elif sum(dealercards) == sum(playercards): print ("It is a tie!")

My Take On The DNA to Codon caculator

This is my take on the DNA converter. I Use a direct approach by writing out all the codons instead of using functions.

#i import randint to make a randomized DNa code from random import randint #i then make variebles to make typing easier A = "A" T = "T" C = "C" G = "G" i = 0 #i make two lists for Rna and Dna SEQ = [A, T, C, G] nSEQ = [] #ask the user to input numbers length = int(input("Enter a number ")) x = len(SEQ)-1 #below this randomizes the letters for i in range(0, length): y = SEQ[randint(0, x)] nSEQ.append(y) # i = i + 1 output = [] #and this is converting to RNA by appending the Rna code to the Dna code for j in range (0, len(nSEQ)): if nSEQ[j] == A: output.append("U") elif nSEQ[j] == T: output.append("A") elif nSEQ[j] == G: output.append("C") else: output.append("G") # i am printing this out so i can find where i went wrong print(nSEQ) print(output) amino ="" #i use the join function to group every three numbers for k in range(0,len(output),3): base3list=output[k:k+3] base3str="".join(base3list) print(base3str) codon = base3str #then i right every single codon and its trio along if (codon == "GCA" or codon == "GCC" or codon == "GCC" or codon == "GCU"): amino = "A" if (codon == "UGC" or codon == "UGU"): amino = "C" if (codon == "GAC" or codon == "GAU"): amino = "D" if (codon == "GAA" or codon == "GAG"): amino = "E" if (codon == "UUC" or codon == "UUU"): amino = "F" if (codon == "GGA" or codon == "GGC" or codon == "GGG" or codon == "GGU"): amino = "G" if (codon == "CAC" or codon == "CAU"): amino = "H" if (codon == "AUA" or codon == "AUC" or codon == "AUU"): amino = "I" if (codon == "AAA" or codon == "AAG"): amino = "K" if (codon == "UUA" or codon == "UUG" or codon == "CUC" or codon == "CUA" or codon == "CUG" or codon == "CUU"): amino = "L" if (codon == "AUG"): amino = "M" if (codon == "AAC" or codon == "AAU"): amino = "N" if (codon == "CCA" or codon == "CCC" or codon == "CCG" or codon == "CCU"): amino = "P" if (codon == "CAG" or codon == "CAA"): amino = "Q" if (codon == "AGA" or codon == "AGG" or codon == "CGA" or codon == "CGC" or codon == "CGG" or codon == "CGU"): amino = "R" if (codon == "AGC" or codon == "AGU" or codon == "UCA" or codon == "UCC" or codon == "UCG" or codon == "UCU"): amino = "S" if (codon == "ACA" or codon == "ACC" or codon == "ACG" or codon == "ACU"): amino = "T" if (codon == "GUA" or codon == "GUC" or codon == "GUG" or codon == "GGU"): amino = "V" if (codon == "UGG" ): amino = "W" if (codon == "UAC" or codon == "UAU" ): amino = "Y"
1 2 3 ... 31