Skip to content

Sourcery Starbot ⭐ refactored gkitg/edu_tmp#1

Open
SourceryAI wants to merge 1 commit into
gkitg:masterfrom
SourceryAI:master
Open

Sourcery Starbot ⭐ refactored gkitg/edu_tmp#1
SourceryAI wants to merge 1 commit into
gkitg:masterfrom
SourceryAI:master

Conversation

@SourceryAI

Copy link
Copy Markdown

Thanks for starring sourcery-ai/sourcery ✨ 🌟 ✨

Here's your pull request refactoring your most popular Python repo.

If you want Sourcery to refactor all your Python repos and incoming pull requests install our bot.

Review changes via command line

To manually merge these changes, make sure you're on the master branch, then run:

git fetch https://github.com/sourcery-ai-bot/edu_tmp master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Comment on lines -14 to +26

# длинный способ
if year % 4 != 0:
print("Обычный")
elif year % 100 == 0:
if year % 400 == 0:
print("Високосный")
else:
print("Обычный")
if (
year % 4 == 0
and year % 100 == 0
and year % 400 == 0
or year % 4 == 0
and year % 100 != 0
):
print("Високосный")
else:
print("Високосный") No newline at end of file
print("Обычный") No newline at end of file

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 15-25 refactored with the following changes:

else:
odd += 1
num = num // 10
num //= 10

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 17-17 refactored with the following changes:

  • Replace assignment with augmented assignment (aug-assign)

while num > 0:
result = result * 10 + num % 10
num = num // 10
num //= 10

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 14-14 refactored with the following changes:

  • Replace assignment with augmented assignment (aug-assign)

return n
sum_n = n + sum_natural(n - 1)
return sum_n
return n if n == 1 else n + sum_natural(n - 1)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function sum_natural refactored with the following changes:

if number < 10:
return number
return number % 10 + sum_digits(number // 10)
return number if number < 10 else number % 10 + sum_digits(number // 10)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function sum_digits refactored with the following changes:

Comment on lines -16 to +17
x = "".join([i for i in x])
y = "".join([i for i in y])
x = "".join(list(x))
y = "".join(list(y))

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function hex_sum refactored with the following changes:

Comment on lines -24 to +25
x = "".join([i for i in x])
y = "".join([i for i in y])
x = "".join(list(x))
y = "".join(list(y))

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function hex_mul refactored with the following changes:

Comment on lines -29 to +35
else:
r = deque()
while x > 15:
d = x % 16
r.appendleft(str(d) if d < 10 else self.hex_letters._fields[d-10])
x = x // 16
r.appendleft(str(x) if x < 10 else self.hex_letters._fields[x-10])
return list(r)
r = deque()
while x > 15:
d = x % 16
r.appendleft(str(d) if d < 10 else self.hex_letters._fields[d-10])
x = x // 16
r.appendleft(str(x) if x < 10 else self.hex_letters._fields[x-10])
return list(r)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function HexCalc.to_hex refactored with the following changes:

hex_number[value] = key

return sum([hex_number[j] * (16 ** i) for i, j in enumerate(num)])
return sum(hex_number[j] * (16 ** i) for i, j in enumerate(num))

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function hex_to_decimal refactored with the following changes:

Comment on lines -21 to +25
for key in pi_func.keys():
for key, size in pi_func.items():
if num <= key:
size = pi_func[key]
break

array = [i for i in range(size)]
array = list(range(size))

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function prime refactored with the following changes:

Comment on lines -7 to +9
for i in range(num):
for _ in range(num):
name = input('name = ')
spam = []
for j in range(1, 5):
spam.append(int(input(f'{j} = ')))
spam = [int(input(f'{j} = ')) for j in range(1, 5)]

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 7-11 refactored with the following changes:

else:
odd += 1
num = num // 10
num //= 10

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 15-32 refactored with the following changes:

  • Replace assignment with augmented assignment [×2] (aug-assign)



orig_list = [random.randint(-100, 100) for i in range(10)]
orig_list = [random.randint(-100, 100) for _ in range(10)]

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 40-40 refactored with the following changes:

Comment on lines -11 to +40
if len(alist)>1:
mid = len(alist)//2
lefthalf = alist[:mid]
righthalf = alist[mid:]

merge_sort(lefthalf)
merge_sort(righthalf)

i=0
j=0
k=0
while i<len(lefthalf) and j<len(righthalf):
if lefthalf[i]<righthalf[j]:
alist[k]=lefthalf[i]
i=i+1
else:
alist[k]=righthalf[j]
j=j+1
k=k+1

while i<len(lefthalf):
if len(alist) <= 1:
return
mid = len(alist)//2
lefthalf = alist[:mid]
righthalf = alist[mid:]

merge_sort(lefthalf)
merge_sort(righthalf)

i=0
j=0
k=0
while i<len(lefthalf) and j<len(righthalf):
if lefthalf[i]<righthalf[j]:
alist[k]=lefthalf[i]
i=i+1
k=k+1

while j<len(righthalf):
i += 1
else:
alist[k]=righthalf[j]
j=j+1
k=k+1
j += 1
k=k+1

while i<len(lefthalf):
alist[k]=lefthalf[i]
i += 1
k=k+1

while j<len(righthalf):
alist[k]=righthalf[j]
j += 1
k=k+1

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function merge_sort refactored with the following changes:

Comment on lines -43 to +44
alist = [random.random()*50 for i in range(n)]
alist = [random.random()*50 for _ in range(n)]

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 43-43 refactored with the following changes:

Comment thread Python/1_home/3.py
Comment on lines -11 to +15
if any(i.isupper() for i in data) and any(i.islower() for i in data) and any(i.isdigit() for i in data):
return True
else:
return False
return (
any(i.isupper() for i in data)
and any(i.islower() for i in data)
and any(i.isdigit() for i in data)
)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function checkio refactored with the following changes:

Comment thread Python/1_home/3.py
Comment on lines -57 to +58
newlst=[]
for i in data:
if data.count(i)>1:
newlst.append(i)
return newlst
return [i for i in data if data.count(i)>1]

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function checkio refactored with the following changes:

Comment thread Python/1_home/3.py
Comment on lines -67 to +64
assert list(checkio([1, 2, 3, 4, 5])) == [], "2nd example"
assert not list(checkio([1, 2, 3, 4, 5])), "2nd example"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 67-67 refactored with the following changes:

Comment thread Python/1_home/4.py
"""
segment = (((x1 - x2) ** 2) + ((y1 - y2) ** 2)) ** 0.5
return segment
return (((x1 - x2) ** 2) + ((y1 - y2) ** 2)) ** 0.5

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function length_segment refactored with the following changes:

Comment thread Python/1_home/4.py
Comment on lines -77 to +82
elif (line_a[0] == line_b[0] and (line_a[0] != line_c[0] or line_b[0] != line_c[0])):
elif line_a[0] == line_b[0]:
print("a || b")
print(0)
elif (line_a[0] == line_c[0] and (line_a[0] != line_b[0] or line_c[0] != line_b[0])):
elif line_a[0] == line_c[0]:
print("a || с")
print(0)
elif (line_b[0] == line_c[0] and (line_b[0] != line_a[0] or line_c[0] != line_a[0])):
elif line_b[0] == line_c[0]:

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function run refactored with the following changes:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant