-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sourcery refactored master branch #1
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,15 @@ | ||
F = open("happy.txt", "r") | ||
# method 1 | ||
val = F.read() | ||
val = val.split() | ||
for i in val: | ||
print(i, "*", end="") | ||
print("\n") | ||
with open("happy.txt", "r") as F: | ||
# method 1 | ||
val = F.read() | ||
val = val.split() | ||
for i in val: | ||
print(i, "*", end="") | ||
print("\n") | ||
|
||
|
||
# method 2 | ||
F.seek(0) | ||
value = F.readlines() | ||
for line in value: | ||
for word in line.split(): | ||
print(word, "*", end="") | ||
F.close() | ||
# method 2 | ||
F.seek(0) | ||
value = F.readlines() | ||
for line in value: | ||
for word in line.split(): | ||
print(word, "*", end="") |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,4 @@ | |
|
||
# calculate the area | ||
area = (s*(s-a)*(s-b)*(s-c)) ** 0.5 | ||
print('The area of the triangle is: ' + area) | ||
print(f'The area of the triangle is: {area}') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,29 @@ | ||
def base_check(xnumber, xbase): | ||
for char in xnumber[len(xnumber ) -1]: | ||
if int(char) >= int(xbase): | ||
return False | ||
return True | ||
return all(int(char) < int(xbase) for char in xnumber[len(xnumber ) -1]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
def convert_from_10(xnumber, xbase, arr, ybase): | ||
if int(xbase) == 2 or int(xbase) == 4 or int(xbase) == 6 or int(xbase) == 8: | ||
if int(xbase) in {2, 4, 6, 8}: | ||
|
||
if xnumber == 0: | ||
return arr | ||
else: | ||
quotient = int(xnumber) // int(xbase) | ||
remainder = int(xnumber) % int(xbase) | ||
arr.append(remainder) | ||
dividend = quotient | ||
convert_from_10(dividend, xbase, arr, base) | ||
quotient, remainder = divmod(int(xnumber), int(xbase)) | ||
arr.append(remainder) | ||
dividend = quotient | ||
convert_from_10(dividend, xbase, arr, base) | ||
elif int(xbase) == 16: | ||
if int(xnumber) == 0: | ||
return arr | ||
else: | ||
quotient = int(xnumber) // int(xbase) | ||
remainder = int(xnumber) % int(xbase) | ||
if remainder > 9: | ||
if remainder == 10: remainder = 'A' | ||
if remainder == 11: remainder = 'B' | ||
if remainder == 12: remainder = 'C' | ||
if remainder == 13: remainder = 'D' | ||
if remainder == 14: remainder = 'E' | ||
if remainder == 15: remainder = 'F' | ||
arr.append(remainder) | ||
dividend = quotient | ||
convert_from_10(dividend, xbase, arr, ybase) | ||
quotient, remainder = divmod(int(xnumber), int(xbase)) | ||
if remainder > 9: | ||
if remainder == 10: remainder = 'A' | ||
if remainder == 11: remainder = 'B' | ||
if remainder == 12: remainder = 'C' | ||
if remainder == 13: remainder = 'D' | ||
if remainder == 14: remainder = 'E' | ||
if remainder == 15: remainder = 'F' | ||
arr.append(remainder) | ||
dividend = quotient | ||
convert_from_10(dividend, xbase, arr, ybase) | ||
Comment on lines
-8
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
def convert_to_10(xnumber, xbase, arr, ybase): | ||
if int(xbase) == 10: | ||
for char in xnumber: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
solution
refactored with the following changes:remove-unnecessary-cast
)aug-assign
)