Skip to content

Commit f3470d4

Browse files
committed
fixing module, code, and code cleanup (reformatted)
1 parent 7afa3dc commit f3470d4

File tree

10 files changed

+218
-169
lines changed

10 files changed

+218
-169
lines changed

Differentiate_List.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
#this code gives the numbers of integers, floats, and strings present in the list
1+
# this code gives the numbers of integers, floats, and strings present in the list
22

33

4-
a= ['Hello',35,'b',45.5,'world',60]
5-
i=f=s=0
4+
a = ["Hello", 35, "b", 45.5, "world", 60]
5+
i = f = s = 0
66
for j in a:
7-
if isinstance(j,int):
8-
i=i+1
9-
elif isinstance(j,float):
10-
f=f+1
7+
if isinstance(j, int):
8+
i = i + 1
9+
elif isinstance(j, float):
10+
f = f + 1
1111
else:
12-
s=s+1
13-
print('Number of integers are:',i)
14-
print('Number of Floats are:',f)
15-
print("numbers of strings are:",s)
12+
s = s + 1
13+
print(f"Number of integers are: {i}")
14+
print(f"Number of Floats are: {f}")
15+
print(f"numbers of strings are: {s}")
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,58 @@
11
import os
2-
import sys
32
import shutil
4-
ext={"web":"css less scss wasm ",
5-
"audio":"aac aiff ape au flac gsm it m3u m4a mid mod mp3 mpa pls ra s3m sid wav wma xm ",
6-
"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 ",
7-
"slide":"ppt odp ","sheet":"ods xls xlsx csv ics vcf ",
8-
"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 ",
9-
"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 ",
10-
"book":"mobi epub azw1 azw3 azw4 azw6 azw cbr cbz ",
11-
"text":"doc docx ebook log md msg odt org pages pdf rtf rst tex txt wpd wps ",
12-
"exec":"exe msi bin command sh bat crx ","font":"eot otf ttf woff woff2 ",
13-
"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 "}
14-
15-
for key,value in ext.items():
16-
value = value.split()
17-
ext[key]=value
183

4+
ext = {
5+
"web": "css less scss wasm ",
6+
"audio": "aac aiff ape au flac gsm it m3u m4a mid mod mp3 mpa pls ra s3m sid wav wma xm ",
7+
"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 ",
8+
"slide": "ppt odp ",
9+
"sheet": "ods xls xlsx csv ics vcf ",
10+
"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 ",
11+
"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 ",
12+
"book": "mobi epub azw1 azw3 azw4 azw6 azw cbr cbz ",
13+
"text": "doc docx ebook log md msg odt org pages pdf rtf rst tex txt wpd wps ",
14+
"exec": "exe msi bin command sh bat crx ",
15+
"font": "eot otf ttf woff woff2 ",
16+
"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 ",
17+
}
18+
19+
for key, value in ext.items():
20+
value = value.split()
21+
ext[key] = value
1922

2023

21-
def add_to_dir(ex,src_path,path):
22-
file_with_ex=os.path.basename(src_path)
23-
file_without_ex=file_with_ex[:file_with_ex.find(ex)-1]
24-
for cat,extensions in ext.items():
24+
def add_to_dir(ex, src_path, path):
25+
file_with_ex = os.path.basename(src_path)
26+
file_without_ex = file_with_ex[: file_with_ex.find(ex) - 1]
27+
for cat, extensions in ext.items():
2528
if ex in extensions:
2629
os.chdir(path)
27-
dest_path=path+'\\'+cat
30+
dest_path = path + "\\" + cat
2831
if cat in os.listdir():
2932
try:
30-
shutil.move(src_path,dest_path)
33+
shutil.move(src_path, dest_path)
3134
except shutil.Error:
32-
renamed_file = rename(file_without_ex,ex,dest_path)
35+
renamed_file = rename(file_without_ex, ex, dest_path)
3336
os.chdir(path)
34-
os.rename(file_with_ex,renamed_file)
37+
os.rename(file_with_ex, renamed_file)
3538
os.chdir(dest_path)
36-
shutil.move(path+'\\'+renamed_file,dest_path)
39+
shutil.move(path + "\\" + renamed_file, dest_path)
3740
else:
3841
os.mkdir(cat)
3942

40-
try :
41-
shutil.move(src_path,dest_path)
43+
try:
44+
shutil.move(src_path, dest_path)
4245
except Exception as e:
4346
print(e)
4447
if os.path.exists(src_path):
4548
os.unlink(src_path)
4649

4750

48-
def rename(search,ex,dest_path):
49-
count=0
51+
def rename(search, ex, dest_path):
52+
count = 0
5053
os.chdir(dest_path)
5154
for filename in os.listdir():
52-
if filename.find(search,0,len(search)-1):
53-
count=count+1
55+
if filename.find(search, 0, len(search) - 1):
56+
count = count + 1
5457

55-
return search+str(count)+'.'+ex
58+
return search + str(count) + "." + ex

Password Generator/pass_gen.py

+38-25
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,72 @@
11
import string as str
22
import secrets
3-
import random #this is the module used to generate random numbers on your given range
4-
class PasswordGenerator():
3+
import random # this is the module used to generate random numbers on your given range
54

5+
6+
class PasswordGenerator:
67
@staticmethod
7-
def gen_sequence(conditions): #must have conditions (in a list format), for each member of the list possible_characters
8-
possible_characters=[str.ascii_lowercase, str.ascii_uppercase, str.digits, str.punctuation]
9-
sequence=""
8+
def gen_sequence(
9+
conditions,
10+
): # must have conditions (in a list format), for each member of the list possible_characters
11+
possible_characters = [
12+
str.ascii_lowercase,
13+
str.ascii_uppercase,
14+
str.digits,
15+
str.punctuation,
16+
]
17+
sequence = ""
1018
for x in range(len(conditions)):
1119
if conditions[x]:
12-
sequence+=possible_characters[x]
20+
sequence += possible_characters[x]
1321
else:
1422
pass
1523
return sequence
1624

1725
@staticmethod
1826
def gen_password(sequence, passlength=8):
19-
password = ''.join((secrets.choice(sequence) for i in range(passlength)))
27+
password = "".join((secrets.choice(sequence) for i in range(passlength)))
2028
return password
2129

22-
class Interface():
23-
has_characters={
24-
"lowercase":True,
25-
"uppercase":True,
26-
"digits":True,
27-
"punctuation":True
30+
31+
class Interface:
32+
has_characters = {
33+
"lowercase": True,
34+
"uppercase": True,
35+
"digits": True,
36+
"punctuation": True,
2837
}
38+
2939
@classmethod
3040
def change_has_characters(cls, change):
3141
try:
32-
cls.has_characters[change] #to check if the specified key exists in the dicitonary
33-
except:
34-
print("Invalid")
42+
cls.has_characters[
43+
change
44+
] # to check if the specified key exists in the dicitonary
45+
except Exception as err:
46+
print(f"Invalid \nan Exception: {err}")
3547
else:
36-
cls.has_characters[change]= not cls.has_characters[change] #automaticly changres to the oppesite value already there
48+
cls.has_characters[change] = not cls.has_characters[
49+
change
50+
] # automaticly changres to the oppesite value already there
3751
print(f"{change} is now set to {cls.has_characters[change]}")
52+
3853
@classmethod
3954
def show_has_characters(cls):
40-
print(cls.has_characters) # print the output
41-
55+
print(cls.has_characters) # print the output
4256

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

61+
4762
def list_to_vertical_string(list):
48-
to_return =""
63+
to_return = ""
4964
for member in list:
5065
to_return += f"{member}\n"
5166
return to_return
5267

53-
class Run():
68+
69+
class Run:
5470
def decide_operation(self):
5571
user_input = input(": ")
5672
try:
@@ -62,11 +78,8 @@ def decide_operation(self):
6278
finally:
6379
print("\n\n")
6480

65-
66-
6781
def run(self):
68-
menu = \
69-
f"""Welcome to the PassGen App!
82+
menu = f"""Welcome to the PassGen App!
7083
Commands:
7184
generate password ->
7285
<lenght of the password>

Pong_game.py

+21-16
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@
8181
sketch.penup()
8282
sketch.hideturtle()
8383
sketch.goto(0, 260)
84-
sketch.write("Left_player : 0 Right_player: 0",
85-
align="center", font=("Courier", 24, "normal"))
84+
sketch.write(
85+
"Left_player : 0 Right_player: 0", align="center", font=("Courier", 24, "normal")
86+
)
8687

8788

8889
# Functions to move paddle vertically
@@ -137,30 +138,34 @@ def paddlebdown():
137138
hit_ball.dy *= -1
138139
left_player += 1
139140
sketch.clear()
140-
sketch.write("Left_player : {} Right_player: {}".format(
141-
left_player, right_player), align="center",
142-
font=("Courier", 24, "normal"))
141+
sketch.write(
142+
"Left_player : {} Right_player: {}".format(left_player, right_player),
143+
align="center",
144+
font=("Courier", 24, "normal"),
145+
)
143146

144147
if hit_ball.xcor() < -500:
145148
hit_ball.goto(0, 0)
146149
hit_ball.dy *= -1
147150
right_player += 1
148151
sketch.clear()
149-
sketch.write("Left_player : {} Right_player: {}".format(
150-
left_player, right_player), align="center",
151-
font=("Courier", 24, "normal"))
152+
sketch.write(
153+
"Left_player : {} Right_player: {}".format(left_player, right_player),
154+
align="center",
155+
font=("Courier", 24, "normal"),
156+
)
152157

153158
# Paddle ball collision
154-
if ((hit_ball.xcor() > 360 and
155-
hit_ball.xcor() < 370) and
156-
(hit_ball.ycor() < right_pad.ycor() + 40 and
157-
hit_ball.ycor() > right_pad.ycor() - 40)):
159+
if (hit_ball.xcor() > 360 and hit_ball.xcor() < 370) and (
160+
hit_ball.ycor() < right_pad.ycor() + 40
161+
and hit_ball.ycor() > right_pad.ycor() - 40
162+
):
158163
hit_ball.setx(360)
159164
hit_ball.dx *= -1
160165

161-
if ((hit_ball.xcor() < -360 and
162-
hit_ball.xcor() > -370) and
163-
(hit_ball.ycor() < left_pad.ycor() + 40 and
164-
hit_ball.ycor() > left_pad.ycor() - 40)):
166+
if (hit_ball.xcor() < -360 and hit_ball.xcor() > -370) and (
167+
hit_ball.ycor() < left_pad.ycor() + 40
168+
and hit_ball.ycor() > left_pad.ycor() - 40
169+
):
165170
hit_ball.setx(-360)
166171
hit_ball.dx *= -1

WeatherGUI.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def getWeather():
1717
airqualitytitle = soup.find('span',class_='_1VMr2').text
1818
sunrise = soup.find('div',class_='_2ATeV').text
1919
sunset = soup.find('div',class_='_2_gJb _2ATeV').text
20-
humidity = soup.find('div',class_='_23DP5').text
20+
# humidity = soup.find('div',class_='_23DP5').text
2121
wind = soup.find('span',class_='_1Va1P undefined').text
2222
pressure = soup.find('span',class_='_3olKd undefined').text
2323
locationlabel.config(text=(location))

diceV2_dynamic.py

+15-7
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ def setSides(self, sides):
1010
if sides > 3:
1111
self.sides = sides
1212
else:
13-
print("This absolutely shouldn't ever happen. The programmer sucks or someone "
14-
"has tweaked with code they weren't supposed to touch!")
13+
print(
14+
"This absolutely shouldn't ever happen. The programmer sucks or someone "
15+
"has tweaked with code they weren't supposed to touch!"
16+
)
1517

1618
def roll(self):
1719
return random.randint(1, self.sides)
@@ -25,12 +27,14 @@ def roll(self):
2527
def checkInput(sides):
2628
try:
2729
if int(sides) != 0:
28-
if float(sides) % int(sides) == 0: # excludes the possibility of inputted floats being rounded.
30+
if (
31+
float(sides) % int(sides) == 0
32+
): # excludes the possibility of inputted floats being rounded.
2933
return int(sides)
3034
else:
3135
return int(sides)
3236

33-
except:
37+
except ValueError:
3438
print("Invalid input!")
3539
return None
3640

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

6064
sides = pickNumber(sides, "How many sides will the dices have?: ", sideLowerLimit)
61-
diceAmount = pickNumber(diceAmount, "How many dices will do you want?: ", diceLowerLimit)
65+
diceAmount = pickNumber(
66+
diceAmount, "How many dices will do you want?: ", diceLowerLimit
67+
)
6268

6369
for i in range(0, diceAmount):
6470
d = Dice()
@@ -71,6 +77,7 @@ def getDices():
7177
# =================================================================
7278
# Output section.
7379

80+
7481
def output():
7582
dices = getDices()
7683
input("Do you wanna roll? press enter")
@@ -83,9 +90,10 @@ def output():
8390
print(rollOutput)
8491

8592
print("do you want to roll again?")
86-
ans = input('press enter to continue, and [exit] to exit')
87-
if ans == 'exit':
93+
ans = input("press enter to continue, and [exit] to exit")
94+
if ans == "exit":
8895
cont = False
8996

97+
9098
if __name__ == "__main__":
9199
output()

0 commit comments

Comments
 (0)