Skip to content

Commit

Permalink
commit some answer
Browse files Browse the repository at this point in the history
  • Loading branch information
zicong tan authored and zicong tan committed Jan 4, 2020
1 parent 0a4d03f commit 248519b
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 1 deletion.
Binary file added .DS_Store
Binary file not shown.
Binary file added Day01-15/.DS_Store
Binary file not shown.
Binary file added Day01-15/code/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion Day01-15/code/Day03/piecewise.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
y = x + 2
else:
y = 5 * x + 3
print('f(%.2f) = %.2f' % (x, y))
print('f(x = %.2f) = %.2f' % (x, y))
30 changes: 30 additions & 0 deletions Day01-15/code/Day04/for4.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,42 @@

num = int(input('请输入一个正整数: '))
end = int(sqrt(num))
# end = int(num) - 1
print('end is %d' %end)
is_prime = True
for x in range(2, end + 1):
print('for x is %d' %x)
if num % x == 0:
is_prime = False
break
if is_prime and num != 1:
print('%d是素数' % num)
else:
print('%d不是素数' % num)

#判断是否素数,只需要试除到其根号对应的数即可
def is_prime(input):
'''
判断是否素数的方法
:param int:
:return:
'''
if not isinstance(input, int):
print('the input is not int!')
raise Exception('the input is not int!')
num = int(input)
end = int(sqrt(input))
is_prime = True
for x in range(2, end + 1):
print('for x is %d' % x)
if num % x == 0:
is_prime = False
break
if is_prime and num != 1:
print('%d是素数' % num)
return True
else:
print('%d不是素数' % num)
return False

is_prime(1.4)
32 changes: 32 additions & 0 deletions Day01-15/code/Day05/my_answer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import time


def get_narcissistic_number():
'''
寻找水仙花数,返回所有的水仙花数列表
:return:
'''
start = time.time()
print(start)
narci_list = []
for num in range(100, 1000):
hundreds = num // 100
tens = num // 10 % 10
units = num % 10
print('the %d is divide into %d %d %d' % (num, hundreds, tens, units))
if hundreds ** 3 + tens ** 3 + units **3 == num:
narci_list.append(num)
print(narci_list)
end = time.time()
print(end)
print('use time is %f second' % (end - start))
return narci_list

def get_perfect_num():
'''
获得完美数
:return:
'''

if __name__ == '__main__':
get_narcissistic_number()
18 changes: 18 additions & 0 deletions Day01-15/day1-15.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
def day_one():
import turtle

turtle.pensize(4)
turtle.pencolor('red')
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.mainloop()


if __name__ == '__main__':

day_one()

0 comments on commit 248519b

Please sign in to comment.