- 1
- 2
if x == 2 or 3: # если x равен 2 или 3
print('Пыщь.')
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+1
if x == 2 or 3: # если x равен 2 или 3
print('Пыщь.')
Вот уже не впервый раз натыкаюсь на подобный "машинный перевод с русского на питон".
−1
While 1:
twy:
throu Excertion(process(input(> ))
except Exxepton as s:
pront(s)
Я напесавл говнокод. Как вам,
0
def count_dupes(serials):
dupes = {}
for item in serials:
if dupes.get(item):
dupes[item] = dupes.get(item) + 1
else:
dupes[item] = 1
return dupes
factory = Functions.get_factory()
for serial in dupes:
for row in factory:
if serial == row['serial']:
result[serial] = row
keys = row.keys()
for key in keys:
if not row[key] == 0:
print(key, row[key])
Парочка моих функций на всеобщее обозрение, что скажете?
0
# Python 2.7
import cgi
print(cgi.parse_qs('a=bagor;+kakoi'))
# {'a': ['bagor']}
# Python 3.7.3
import urllib.parse
print(urllib.parse.parse_qs('a=bagor;+kakoi'))
# {'a': ['bagor']}
# Python 3.9.10
import urllib.parse
print(urllib.parse.parse_qs('a=bagor;+kakoi'))
# {'a': ['bagor; kakoi']}
Что, блядь, это за хуета???
Переводил программу на Python3 и пол дня потратил в попытках понять почему блядь тесты сломались.
Какой-то петух завязался, на ';' сепаратор, который обрезается.
https://docs.python.org/3/library/urllib.parse.html
Changed in version 3.10: Added separator parameter with the default value of &. Python versions earlier than Python 3.10 allowed using both ; and & as query parameter separator. This has been changed to allow only a single separator key, with & as the default separator.
И у меня не 3.10, но да похуй.
Как мне теперь закостылять это говно, не меняя данные?
0
def drawPoints(self, qp):
pen = QPen()
if self.flag1:
color1 = QColor('red')
pen.setColor(color1)
if self.flag2:
color2 = QColor('green')
pen.setColor(color2)
if self.flag3:
color3 = QColor('yellow')
pen.setColor(color3)
if self.flag4:
color4 = QColor('blue')
pen.setColor(color4)
if self.flag5:
color5 = QColor('purple')
pen.setColor(color5)
if self.flag6:
color6 = QColor('brown')
pen.setColor(color6)
if self.n_flag:
pen.setWidth(5)
if self.n_flag2:
pen.setWidth(10)
if self.n_flag3:
pen.setWidth(15)
if self.n_flag4:
pen.setWidth(20)
qp.setPen(pen)
qp.drawPoint(QtCore.QPoint(self.point))
def onClicked(self):
self.flag1 = True
self.update()
def onClicked2(self):
self.flag2 = True
self.update()
def onClicked3(self):
self.flag3 = True
self.update()
def onClicked4(self):
self.flag4 = True
self.update()
def onClicked5(self):
self.flag5 = True
self.update()
def onClicked6(self):
self.flag6 = True
self.update()
def onClicked7(self):
self.n_flag = True
self.update()
def onClicked8(self):
self.n_flag2 = True
self.update()
def onClicked9(self):
self.n_flag3 = True
self.update()
def onClicked10(self):
self.n_flag4 = True
self.update()
Больше onClicked БОЛЬШЕ
0
def res_horizontal(self, btn):
self.im = Image.open(self.new_img)
if btn.text() == "320x240":
self.new_im = self.im.resize((320, 240))
elif btn.text() == '1024x600':
self.new_im = self.im.resize((1024, 600))
elif btn.text() == '1280x720':
self.new_im = self.im.resize((1280, 720))
elif btn.text() == '1440x900':
self.new_im = self.im.resize((1440, 900))
elif btn.text() == '1600x1024':
self.new_im = self.im.resize((1600, 1024))
elif btn.text() == '1920x1080':
self.new_im = self.im.resize((1920, 1080))
elif btn.text() == '2048x1536':
self.new_im = self.im.resize((2048, 1536))
elif btn.text() == '2560x1440':
self.new_im = self.im.resize((2560, 440))
elif btn.text() == '3840x2160':
self.new_im = self.im.resize((3840, 2160))
elif btn.text() == '4096x2160':
self.new_im = self.im.resize((4096, 2160))
elif btn.text == '800x480':
self.new_im = self.im.resize((800, 480))
self.new_im.save(self.new_img)
def res_vertical(self, btn):
self.im = Image.open(self.new_img)
if btn.text() == '240x320':
self.new_im = self.im.resize((240, 320))
elif btn.text() == '480x800':
self.new_im = self.im.resize((480, 800))
elif btn.text() == '600x1024':
self.new_im = self.im.resize((600, 1024))
elif btn.text() == '720x1280':
self.new_im = self.im.resize((720, 1280))
elif btn.text() == '900x1440':
self.new_im = self.im.resize((900, 1440))
elif btn.text() == '1024x1600':
self.new_im = self.im.resize((1024, 1600))
elif btn.text() == '1080x1920':
self.new_im = self.im.resize((1080, 1920))
elif btn.text() == '1536x2048':
self.new_im = self.im.resize((1536, 2048))
elif btn.text() == '1440x2560':
self.new_im = self.im.resize((1440, 2560))
elif btn.text() == '2160x3840':
self.new_im = self.im.resize((2160, 3840))
elif btn.text() == '2160x4096':
self.new_im = self.im.resize((2160, 4096))
self.new_im.save(self.new_img)
def res_square(self, btn):
self.im = Image.open(self.new_img)
if btn.text() == '320x320':
self.new_im = self.im.resize((320, 320))
elif btn.text() == '800x800':
self.new_im = self.im.resize((800, 800))
elif btn.text() == '1280x1280':
self.new_im = self.im.resize((1280, 1280))
elif btn.text() == '1024x1024':
self.new_im = self.im.resize((1024, 1024))
elif btn.text() == '1600x1600':
self.new_im = self.im.resize((1600, 1600))
elif btn.text() == '1440x1440':
self.new_im = self.im.resize((1440, 1440))
elif btn.text() == '1920x1920':
self.new_im = self.im.resize((1920, 1920))
elif btn.text() == '2048x2048':
self.new_im = self.im.resize((2048, 2048))
elif btn.text() == '3840x3840':
self.new_im = self.im.resize((3840, 3840))
elif btn.text() == '2560x2560':
self.new_im = self.im.resize((2560, 2560))
elif btn.text() == '4096x4096':
self.new_im = self.im.resize((4096, 4096))
self.new_im.save(self.new_img)
Давным давно на pyqt писал этот говнокод, теперь ржу над ним
0
#!/usr/bin/env python3
import subprocess as sp
lines_pipe = sp.Popen(('xinput', 'list'), stdout=sp.PIPE)
id_line = str(sp.check_output(('grep', 'Touchpad'), stdin=lines_pipe.stdout))
a = id_line.index("id=") + 3
b = a
while id_line[b] in set(list("0123456789")):
b += 1
id = id_line[a:b]
status_pipe = sp.Popen(('xinput', 'list-props', id), stdout=sp.PIPE)
sp.run(('xinput', ['enable', 'disable'][int(str(sp.check_output(('grep', 'Device Enabled'), stdin=status_pipe.stdout))[-4]=='1')], id))
Предыдущий прыщескрипт на bash соснул, так как захардкоженный "id", оказалось, иногда может меняться, поэтому скрипт был благополучно перенесён на "Python".
0
def number_to_words(n):
if n == 1:
print('один')
exit()
elif n == 2:
print('два')
exit()
elif n == 3:
print('три')
exit()
elif n == 4:
print('четыре')
exit()
elif n == 5:
print('пять')
exit()
elif n == 6:
print('шесть')
exit()
elif n == 7:
print('семь')
exit()
elif n == 8:
print('восемь')
exit()
elif n == 9:
print('девять')
exit()
elif n == 10:
print('десять')
exit()
elif n == 11:
print('одиннадцать')
exit()
elif n == 12:
print('двенадцать')
exit()
elif n == 13:
print('тринадцать')
exit()
elif n == 14:
print('четырнадцать')
exit()
elif n == 15:
print('пятнадцать')
exit()
elif n == 16:
print('шестнадцать')
exit()
elif n == 17:
print('семнадцать')
exit()
elif n == 18:
print('восемнадцать')
exit()
elif n == 19:
print('девятнадцать')
exit()
elif n == 20:
print('двадцать')
exit()
elif n == 21:
print('двадцать один')
exit()
elif n == 22:
print('двадцать два')
exit()
elif n == 23:
print('двадцать три')
exit()
elif n == 24:
print('двадцать четыре')
exit()
elif n == 25:
print('двадцать пять')
exit()
elif n == 26:
print('двадцать шесть')
exit()
elif n == 27:
print('двадцать семь')
exit()
elif n == 28:
print('двадцать восемь')
exit()
elif n == 29:
print('двадцать девять')
exit()
elif n == 30:
print('тридцать')
exit()
elif n == 31:
print('тридцать один')
exit()
elif n == 32:
print('тридцать два')
exit()
так до 99. Оригинал: https://www.cyberforum.ru/python-beginners/thread2390750.html
P.S. exit-ы то зачем????
+1
a = int(input('Введите число A: '))
b = int(input('Введите число B: '))
c = int(input('Введите число C: '))
d = int(input('Введите число D: '))
if a % 2 == 0 and b % 2 == 0 and c % 2 == 0 and d % 2 == 0:
print ('Все числа четные')
elif a % 2 != 0 and b % 2 == 0 and c % 2 == 0 and d % 2 == 0:
print ('Все числа четные, кроме числа А')
elif a % 2 == 0 and b % 2 != 0 and c % 2 == 0 and d % 2 == 0:
print ('Все числа четные, кроме числа B')
elif a % 2 == 0 and b % 2 == 0 and c % 2 != 0 and d % 2 == 0:
print ('Все числа четные, кроме числа C')
elif a % 2 == 0 and b % 2 == 0 and c % 2 == 0 and d % 2 != 0:
print ('Все числа четные, кроме числа D')
elif a % 2 != 0 and b % 2 != 0 and c % 2 == 0 and d % 2 == 0:
print ('Числа C и D четные, а А и B нет')
elif a % 2 != 0 and b % 2 == 0 and c % 2 != 0 and d % 2 == 0:
print ('Числа B и D четные, а А и C нет')
elif a % 2 != 0 and b % 2 == 0 and c % 2 == 0 and d % 2 != 0:
print ('Числа B и C четные, а А и D нет')
# with B
elif a % 2 == 0 and b % 2 != 0 and c % 2 != 0 and d % 2 == 0:
print ('Числа A и D четные, а B и C нет')
elif a % 2 != 0 and b % 2 == 0 and c % 2 != 0 and d % 2 == 0:
print ('Числа B и D четные, а А и C нет')
elif a % 2 != 0 and b % 2 == 0 and c % 2 == 0 and d % 2 != 0:
print ('Числа B и C четные, а А и D нет')
elif a % 2 == 0 and b % 2 == 0 and c % 2 != 0 and d % 2 != 0:
print ('Числа A и B четные, а C и D нет')
elif a % 2 == 0 and b % 2 != 0 and c % 2 != 0 and d % 2 != 0:
print ('Все числа нечетные, кроме числа А')
elif a % 2 != 0 and b % 2 == 0 and c % 2 != 0 and d % 2 != 0:
print ('Все числа нечетные, кроме числа B')
elif a % 2 != 0 and b % 2 != 0 and c % 2 == 0 and d % 2 != 0:
print ('Все числа нечетные, кроме числа C')
elif a % 2 != 0 and b % 2 != 0 and c % 2 != 0 and d % 2 == 0:
print ('Все числа нечетные, кроме числа D')
else:
print ('Введите только целые числа')
0
def foo(n):
f = True
k = n % 10
while n > k:
n //= 10
if n % 10 != k:
f = False
break
return f
array = [
[22, 14, 8, 14],
[22, 13, 70, 95],
[22, 12, 51, 10], # Для тестирования
[20, 11, 51, 56],
[49, 10, 36, 85]
]
f2 = True
for i in range(len(array[0])):
c = 0
for j in range(len(array)):
if foo(array[j][i]):
c += 1
if c > 3:
f2 = False
break
print("True" if f2 else "False")