Skip to content
Permalink
Browse files
Refractoring File System
  • Loading branch information
Sergiu Harjau committed Oct 3, 2018
1 parent 7d05ef7 commit dd97efdb68e43d24f727c2062e59f4c0dd648d98
Show file tree
Hide file tree
Showing 145 changed files with 1,514,263 additions and 0 deletions.
@@ -0,0 +1,33 @@
hour= input("What is the hour(24 hour format)? ")
if int(hour)<0 or int(hour)>24:
print("Good try. I meant a real hour.")
quit()
minutes= input("And how many minutes? ")
if int(minutes) <0 or int(minutes)>=60:
print("Mate, are you even trying.")
quit()
if (int(minutes)<7.5 and int(minutes)>0) or (int(minutes)<60 and int(minutes)>52.5):
minutes=""
else:
if (int(minutes)>7.5) and (int(minutes)<22.5):
minutes=" quarter past"
else:
if (int(minutes)>22.5) and (int(minutes)<37.5):
minutes=" half past"
else:
if (int(minutes)>37.5) and (int(minutes)<52.5):
minutes=" quarter to"
if minutes == "quarter to":
if int(hour)<12:
hour=int(hour) + 1
print("The time is about" + str(minutes) + " " + str(hour) + " in the morning")
else:
hour=int(hour) - 12
hour=int(hour) + 1
print("The time is about" + str(minutes) + " " + str(hour) + " in the afternoon")
else:
if int(hour)<12:
print("The time is about" + str(minutes) + " " + str(hour) + " in the morning")
else:
hour=int(hour) - 12
print("The time is about" + str(minutes) + " " + str(hour) + " in the afternoon")
@@ -0,0 +1,112 @@

def listToString(list1):
"""This function takes a list and turns it into a string"""
result=list1
result="".join(result)
return(result)

def stringToList(value):
"""This function takes a string and inputs it to a list"""
list1=[]
y=len(value)
x=0
while x<y:
list1.append(value[x])
x=x+1
return(list1)

def encryptionTool(string,key):
"""This function takes a string and a key and outputs the string as encrypted"""
list1= stringToList(string) #we take the string and turn it into a list
y=len(list1)
x=0
x2=0
finalList=list1
while x<y: #this ensures that the index is never out of bounds (x is the length of its own list)
for z in range (0,26): #this ensures that we work through every reference (a through z)
if list1[x]==reference[z]: #we check every letter we have with the reference
if (z+key)>25: #when it finds a match, it checks for a runtime error (regarding index)
key2=(z-25)+key -1
finalList[x]=reference[key2]
else:
finalList[x]=reference[z+key]
break
elif list1[x]==reference2[z]:
if (z+key)>25:
key2=(z-25)+key -1
finalList[x]=reference2[key2]
else:
finalList[x]=reference2[z+key]
break
elif list1[x]==" ":
finalList.append(" ")
break
else:
pass
x=x+1
result=listToString(finalList) #we take the list and make it a string
return(result)

def decodingTool(string, key):
"""This function takes a string and a key, and returns the decrypted string"""
list1= stringToList(string)
y=len(list1)
x=0
x2=0
finalList=list1
while x<y:
for z in range (0,26):
if list1[x]==reference[z]:
if (z-key)<0:
key2=26-(key-z)
finalList[x]=reference[key2]
else:
finalList[x]=reference[z-key]
break
elif list1[x]==reference2[z]:
if (z-key)<0:
key2=26-(key-z)
finalList[x]=reference2[key2]
else:
finalList[x]=reference2[z-key]
break
elif list1[x]==" ":
finalList.append(" ")
break
else:
pass
x=x+1
result=listToString(finalList)
return(result)

reference=["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"]

reference2=["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"]

xy=1

while xy==1:
decision=int(input(" \nTo encrypt, press 1. \nTo decrypt, press 0.\n"))
if decision==1:
value=input("What do you want to encrypt? \n")
key=int(input("Choose a key from 1 through 26:\n"))
message= encryptionTool(value,key)
print(" \nYour encrypted message is: \n" +str(message) +" \n" )
xy=int(input("Do you want to keep using this program?\n1-yes\n0-no\n"))
elif decision==0:
value=input("What do you want to decrypt? \n")
key=int(input("Choose a key from 1 through 26:\n"))
message= decodingTool(value, key)
print(" \nYour decrypted message is: \n" + str(message) + " \n")
xy=int(input("Do you want to keep using this program?\n1-yes\n0-no\n"))
else:
print("Please input a valid value.")









@@ -0,0 +1,39 @@

def makeList(value,x):
"""Function to make a list of size (1,value)"""
while x<value:
list1.append(x+1) #increments itself until it reaches the desired value
x=x+1
return(list1)

primenumbers=[2,3,5,7,9,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101]

def makePrimeNumbers(list1,value):
"""Function that takes a list and outputs the prime numbers in it"""
for i in primenumbers:
for z in range (2,value): #starting at two because otherwise we delete the first prime
result=i*z #using the method described in the labsheet, i is a prime number
if result >value:
break #if the results is bigger than what's in the list, break the loop, prevents an error
if result in list1: # part of the method, remove multiples of prime from the list
list1.remove(result)
else:
continue #if it's not in the list, just continue the iteration, prevents an error
return(list1)

#To be noted that this program works because a prime is never the multiple of any two numbers, so it never deletes any primes, only other numbers

x=1 #we start the numbers from 2, x=1 here, and x=x+1 upstairs, because 1 is not a prime

value=int(input("Enter a number: "))

list1=[] #prevents an error message

list1=makePrimeNumbers(makeList(value,x),value) #self explanatory

print("Here are your prime numbers!!\n"+str(list1)) #the \n breaks the line, starts a new one





@@ -0,0 +1,37 @@

def makeTable(x,y):
"""Function that makes a times table of size x,x"""
for i in range(-1,x+1): #starts at -1 because we need a special case (-1)
if i==-1: #special case, prints the first row of numbers and the delimitator
print("x | ",end="")
for z in range (0,x+1): #prints the numbers
if z > 9:
print(z, end=" ") #makes sure the spacing lines up with the number of digits
else:
print(z, end=" ") #single digits, more space
z=z+1
print("") #breaks the "end" thing, starts a new line
k=6.1*x #mathematical magic trying to get the right number of lines (it works)
k=int(round(k,0))+5 #makes sure we get an even one, +mathsy stuff
for z in range (0,k): #prints the actual lines
print("_", end="")
else:
if i > 9:
print(i, end=" | ") #any >9 or >99 means I am getting the spacing right
else:
print(i, end= " | ")
for j in range (0,y+1):
if i==-1:
continue #in the special case, skip it
if i*j>99:
print(i*j, end=" ")
elif i*j>9:
print(i*j, end=" ")
else:
print(i*j, end=" ")
print("") #no need for return because it is meant to print

x=int(input("Pick x: "))
y=x #I wanted to firstly make it of range x,y, but it failed pretty bad, I resorted to making it x * x. therefore y=x

makeTable(x,y) #calls the function, starts the process

0 comments on commit dd97efd

Please sign in to comment.