Skip to content

Commit

Permalink
fixing module, code, and code cleanup (reformatted)
Browse files Browse the repository at this point in the history
  • Loading branch information
slowy07 committed Jul 24, 2021
1 parent 7afa3dc commit f3470d4
Show file tree
Hide file tree
Showing 10 changed files with 218 additions and 169 deletions.
22 changes: 11 additions & 11 deletions Differentiate_List.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#this code gives the numbers of integers, floats, and strings present in the list
# this code gives the numbers of integers, floats, and strings present in the list


a= ['Hello',35,'b',45.5,'world',60]
i=f=s=0
a = ["Hello", 35, "b", 45.5, "world", 60]
i = f = s = 0
for j in a:
if isinstance(j,int):
i=i+1
elif isinstance(j,float):
f=f+1
if isinstance(j, int):
i = i + 1
elif isinstance(j, float):
f = f + 1
else:
s=s+1
print('Number of integers are:',i)
print('Number of Floats are:',f)
print("numbers of strings are:",s)
s = s + 1
print(f"Number of integers are: {i}")
print(f"Number of Floats are: {f}")
print(f"numbers of strings are: {s}")
65 changes: 34 additions & 31 deletions Downloaded Files Organizer/move_to_directory.py
Original file line number Diff line number Diff line change
@@ -1,55 +1,58 @@
import os
import sys
import shutil
ext={"web":"css less scss wasm ",
"audio":"aac aiff ape au flac gsm it m3u m4a mid mod mp3 mpa pls ra s3m sid wav wma xm ",
"code":"c cc class clj cpp cs cxx el go h java lua m m4 php pl po py rb rs swift vb vcxproj xcodeproj xml diff patch html js ",
"slide":"ppt odp ","sheet":"ods xls xlsx csv ics vcf ",
"image":"3dm 3ds max bmp dds gif jpg jpeg png psd xcf tga thm tif tiff ai eps ps svg dwg dxf gpx kml kmz webp ",
"archiv":"7z a apk ar bz2 cab cpio deb dmg egg gz iso jar lha mar pea rar rpm s7z shar tar tbz2 tgz tlz war whl xpi zip zipx xz pak ",
"book":"mobi epub azw1 azw3 azw4 azw6 azw cbr cbz ",
"text":"doc docx ebook log md msg odt org pages pdf rtf rst tex txt wpd wps ",
"exec":"exe msi bin command sh bat crx ","font":"eot otf ttf woff woff2 ",
"video":"3g2 3gp aaf asf avchd avi drc flv m2v m4p m4v mkv mng mov mp2 mp4 mpe mpeg mpg mpv mxf nsv ogg ogv ogm qt rm rmvb roq srt svi vob webm wmv yuv "}

for key,value in ext.items():
value = value.split()
ext[key]=value

ext = {
"web": "css less scss wasm ",
"audio": "aac aiff ape au flac gsm it m3u m4a mid mod mp3 mpa pls ra s3m sid wav wma xm ",
"code": "c cc class clj cpp cs cxx el go h java lua m m4 php pl po py rb rs swift vb vcxproj xcodeproj xml diff patch html js ",
"slide": "ppt odp ",
"sheet": "ods xls xlsx csv ics vcf ",
"image": "3dm 3ds max bmp dds gif jpg jpeg png psd xcf tga thm tif tiff ai eps ps svg dwg dxf gpx kml kmz webp ",
"archiv": "7z a apk ar bz2 cab cpio deb dmg egg gz iso jar lha mar pea rar rpm s7z shar tar tbz2 tgz tlz war whl xpi zip zipx xz pak ",
"book": "mobi epub azw1 azw3 azw4 azw6 azw cbr cbz ",
"text": "doc docx ebook log md msg odt org pages pdf rtf rst tex txt wpd wps ",
"exec": "exe msi bin command sh bat crx ",
"font": "eot otf ttf woff woff2 ",
"video": "3g2 3gp aaf asf avchd avi drc flv m2v m4p m4v mkv mng mov mp2 mp4 mpe mpeg mpg mpv mxf nsv ogg ogv ogm qt rm rmvb roq srt svi vob webm wmv yuv ",
}

for key, value in ext.items():
value = value.split()
ext[key] = value


def add_to_dir(ex,src_path,path):
file_with_ex=os.path.basename(src_path)
file_without_ex=file_with_ex[:file_with_ex.find(ex)-1]
for cat,extensions in ext.items():
def add_to_dir(ex, src_path, path):
file_with_ex = os.path.basename(src_path)
file_without_ex = file_with_ex[: file_with_ex.find(ex) - 1]
for cat, extensions in ext.items():
if ex in extensions:
os.chdir(path)
dest_path=path+'\\'+cat
dest_path = path + "\\" + cat
if cat in os.listdir():
try:
shutil.move(src_path,dest_path)
shutil.move(src_path, dest_path)
except shutil.Error:
renamed_file = rename(file_without_ex,ex,dest_path)
renamed_file = rename(file_without_ex, ex, dest_path)
os.chdir(path)
os.rename(file_with_ex,renamed_file)
os.rename(file_with_ex, renamed_file)
os.chdir(dest_path)
shutil.move(path+'\\'+renamed_file,dest_path)
shutil.move(path + "\\" + renamed_file, dest_path)
else:
os.mkdir(cat)

try :
shutil.move(src_path,dest_path)
try:
shutil.move(src_path, dest_path)
except Exception as e:
print(e)
if os.path.exists(src_path):
os.unlink(src_path)


def rename(search,ex,dest_path):
count=0
def rename(search, ex, dest_path):
count = 0
os.chdir(dest_path)
for filename in os.listdir():
if filename.find(search,0,len(search)-1):
count=count+1
if filename.find(search, 0, len(search) - 1):
count = count + 1

return search+str(count)+'.'+ex
return search + str(count) + "." + ex
63 changes: 38 additions & 25 deletions Password Generator/pass_gen.py
Original file line number Diff line number Diff line change
@@ -1,56 +1,72 @@
import string as str
import secrets
import random #this is the module used to generate random numbers on your given range
class PasswordGenerator():
import random # this is the module used to generate random numbers on your given range


class PasswordGenerator:
@staticmethod
def gen_sequence(conditions): #must have conditions (in a list format), for each member of the list possible_characters
possible_characters=[str.ascii_lowercase, str.ascii_uppercase, str.digits, str.punctuation]
sequence=""
def gen_sequence(
conditions,
): # must have conditions (in a list format), for each member of the list possible_characters
possible_characters = [
str.ascii_lowercase,
str.ascii_uppercase,
str.digits,
str.punctuation,
]
sequence = ""
for x in range(len(conditions)):
if conditions[x]:
sequence+=possible_characters[x]
sequence += possible_characters[x]
else:
pass
return sequence

@staticmethod
def gen_password(sequence, passlength=8):
password = ''.join((secrets.choice(sequence) for i in range(passlength)))
password = "".join((secrets.choice(sequence) for i in range(passlength)))
return password

class Interface():
has_characters={
"lowercase":True,
"uppercase":True,
"digits":True,
"punctuation":True

class Interface:
has_characters = {
"lowercase": True,
"uppercase": True,
"digits": True,
"punctuation": True,
}

@classmethod
def change_has_characters(cls, change):
try:
cls.has_characters[change] #to check if the specified key exists in the dicitonary
except:
print("Invalid")
cls.has_characters[
change
] # to check if the specified key exists in the dicitonary
except Exception as err:
print(f"Invalid \nan Exception: {err}")
else:
cls.has_characters[change]= not cls.has_characters[change] #automaticly changres to the oppesite value already there
cls.has_characters[change] = not cls.has_characters[
change
] # automaticly changres to the oppesite value already there
print(f"{change} is now set to {cls.has_characters[change]}")

@classmethod
def show_has_characters(cls):
print(cls.has_characters) # print the output

print(cls.has_characters) # print the output

def generate_password(self, lenght):
sequence = PasswordGenerator.gen_sequence(list(self.has_characters.values()))
print(PasswordGenerator.gen_password(sequence, lenght))


def list_to_vertical_string(list):
to_return =""
to_return = ""
for member in list:
to_return += f"{member}\n"
return to_return

class Run():

class Run:
def decide_operation(self):
user_input = input(": ")
try:
Expand All @@ -62,11 +78,8 @@ def decide_operation(self):
finally:
print("\n\n")



def run(self):
menu = \
f"""Welcome to the PassGen App!
menu = f"""Welcome to the PassGen App!
Commands:
generate password ->
<lenght of the password>
Expand Down
37 changes: 21 additions & 16 deletions Pong_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@
sketch.penup()
sketch.hideturtle()
sketch.goto(0, 260)
sketch.write("Left_player : 0 Right_player: 0",
align="center", font=("Courier", 24, "normal"))
sketch.write(
"Left_player : 0 Right_player: 0", align="center", font=("Courier", 24, "normal")
)


# Functions to move paddle vertically
Expand Down Expand Up @@ -137,30 +138,34 @@ def paddlebdown():
hit_ball.dy *= -1
left_player += 1
sketch.clear()
sketch.write("Left_player : {} Right_player: {}".format(
left_player, right_player), align="center",
font=("Courier", 24, "normal"))
sketch.write(
"Left_player : {} Right_player: {}".format(left_player, right_player),
align="center",
font=("Courier", 24, "normal"),
)

if hit_ball.xcor() < -500:
hit_ball.goto(0, 0)
hit_ball.dy *= -1
right_player += 1
sketch.clear()
sketch.write("Left_player : {} Right_player: {}".format(
left_player, right_player), align="center",
font=("Courier", 24, "normal"))
sketch.write(
"Left_player : {} Right_player: {}".format(left_player, right_player),
align="center",
font=("Courier", 24, "normal"),
)

# Paddle ball collision
if ((hit_ball.xcor() > 360 and
hit_ball.xcor() < 370) and
(hit_ball.ycor() < right_pad.ycor() + 40 and
hit_ball.ycor() > right_pad.ycor() - 40)):
if (hit_ball.xcor() > 360 and hit_ball.xcor() < 370) and (
hit_ball.ycor() < right_pad.ycor() + 40
and hit_ball.ycor() > right_pad.ycor() - 40
):
hit_ball.setx(360)
hit_ball.dx *= -1

if ((hit_ball.xcor() < -360 and
hit_ball.xcor() > -370) and
(hit_ball.ycor() < left_pad.ycor() + 40 and
hit_ball.ycor() > left_pad.ycor() - 40)):
if (hit_ball.xcor() < -360 and hit_ball.xcor() > -370) and (
hit_ball.ycor() < left_pad.ycor() + 40
and hit_ball.ycor() > left_pad.ycor() - 40
):
hit_ball.setx(-360)
hit_ball.dx *= -1
2 changes: 1 addition & 1 deletion WeatherGUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def getWeather():
airqualitytitle = soup.find('span',class_='_1VMr2').text
sunrise = soup.find('div',class_='_2ATeV').text
sunset = soup.find('div',class_='_2_gJb _2ATeV').text
humidity = soup.find('div',class_='_23DP5').text
# humidity = soup.find('div',class_='_23DP5').text
wind = soup.find('span',class_='_1Va1P undefined').text
pressure = soup.find('span',class_='_3olKd undefined').text
locationlabel.config(text=(location))
Expand Down
22 changes: 15 additions & 7 deletions diceV2_dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ def setSides(self, sides):
if sides > 3:
self.sides = sides
else:
print("This absolutely shouldn't ever happen. The programmer sucks or someone "
"has tweaked with code they weren't supposed to touch!")
print(
"This absolutely shouldn't ever happen. The programmer sucks or someone "
"has tweaked with code they weren't supposed to touch!"
)

def roll(self):
return random.randint(1, self.sides)
Expand All @@ -25,12 +27,14 @@ def roll(self):
def checkInput(sides):
try:
if int(sides) != 0:
if float(sides) % int(sides) == 0: # excludes the possibility of inputted floats being rounded.
if (
float(sides) % int(sides) == 0
): # excludes the possibility of inputted floats being rounded.
return int(sides)
else:
return int(sides)

except:
except ValueError:
print("Invalid input!")
return None

Expand Down Expand Up @@ -58,7 +62,9 @@ def getDices():
diceLowerLimit = 1 # Do Not Touch!

sides = pickNumber(sides, "How many sides will the dices have?: ", sideLowerLimit)
diceAmount = pickNumber(diceAmount, "How many dices will do you want?: ", diceLowerLimit)
diceAmount = pickNumber(
diceAmount, "How many dices will do you want?: ", diceLowerLimit
)

for i in range(0, diceAmount):
d = Dice()
Expand All @@ -71,6 +77,7 @@ def getDices():
# =================================================================
# Output section.


def output():
dices = getDices()
input("Do you wanna roll? press enter")
Expand All @@ -83,9 +90,10 @@ def output():
print(rollOutput)

print("do you want to roll again?")
ans = input('press enter to continue, and [exit] to exit')
if ans == 'exit':
ans = input("press enter to continue, and [exit] to exit")
if ans == "exit":
cont = False


if __name__ == "__main__":
output()
Loading

0 comments on commit f3470d4

Please sign in to comment.