# Python100道练习题（不定期更新中）

# 100道练习题
"""
2020.7.9 笔记
"""
"""

"""

def exercise_1():
arr = []
for i in range(1, 5):
for j in range(1, 5):
for k in range(1, 5):
num = i * 100 + j * 10 + k
if i != j and i != k and j != k:
arr.append(num)

print(len(arr), arr)

# exercise_1()
"""

itertools：combinations 组合，permutations 排列， combinations_with_replace 放回式组合， product 笛卡尔积
"""

def exercise_1_1():
import itertools
temp = list(itertools.permutations([1, 2, 3, 4], 3))
arr = [t[0] * 100 + t[1] * 10 + t[0] for t in temp]
print(len(arr), arr)

# exercise_1_1()

"""

20万到40万之间时，高于20万元的部分，可提成5%；
40万到60万之间时高于40万元的部分，可提成3%；
60万到100万之间时，高于60万元的部分，可提成1.5%；

"""

def exercise_2():
arr = [1000000, 600000, 400000, 200000, 100000, 0]
rat = [0.01, 0.015, 0.03, 0.05, 0.075, 0.1]
bonus = 0

for i in range(len(arr)):
if money > arr[i]:
bonus += (money - arr[i]) * rat[i]
money = arr[i]

print(bonus)

# exercise_2()

"""

m + 100 >= 0，m >= -100
(x + 1)^2 - x^2 = 168，得x = 83.5，上界为84，可以取7000
"""

def exercise_3():
import math
for i in range(-100, 7000):
m = math.sqrt(i + 100)
n = math.sqrt(i + 100 + 168)
if m % 1 == 0 and n % 1 == 0:
print(i)

# exercise_3()

def exercise_3_1():
arr = []
res = []
for i in range(84):
arr.append(i ** 2)
for elem in arr:
if elem + 168 in arr:
res.append(elem - 100)

print(len(res), res)

# exercise_3_1()

"""

tm_year     年
tm_mon      月(1~12)
tm_mday     日(1~31)
tm_hour     时(0~23)
tm_min      分(0~59)
tm_sec      秒(0~61, 60或61是闰秒)
tm_wday     星期(0~6, 0是周一)
tm_yday     第几天(1~366)
tm_isdst    夏令时
"""

def exercise_4():
import time
res = time.strptime(data, '%Y-%m-%d')  # 格式化
print(res.tm_yday)

# exercise_4()

"""

"""

"""

"""

"""

"""

def exercise_7():
a = [1, 2, 3]
b = a[:]
c = a  # 注意区别
a[0] = 4
print(id(a), id(b), id(c), sep='\n')
print(a, b, c, sep='\n')

# exercise_7()

"""

"""

def exercise_8():
for i in range(1, 10):
for j in range(1, 10):
if j <= i:
st = '{%d} * {%d} = {%d}' % (j, i, j * i)
print('%-20s' % st, end=' ')
print('')

# exercise_8()

def exercise_8_1():
for i in range(1, 10):
for j in range(1, i + 1):
print("{0} * {1} = {2}".format(j, i, i * j), end="\t")
print('')

# exercise_8_1()

"""

"""

def exercise_9():
import time
a = time.time()
time.sleep(1)
b = time.time()
print(b - a)

# exercise_9()

"""

"""

def exercise_10():
import time
a = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
print(a)
time.sleep(1)
b = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
print(b)

# exercise_10()

"""

"""

def exercise_11():
month = input("Please input the number of mouths:")
m_1 = 1
m_2 = 0
m_3 = 0
for i in range(1, int(month) + 1):  # 注意mouth的类型
m_3 += m_2
m_2 = m_1
m_1 = m_3
print(i, m_1 + m_2 + m_3)

# exercise_11()

"""

"""

def exercise_12():
import math
arr = []
for i in range(101, 201):
flag = False
for j in range(2, int(math.sqrt(i)) + 1):
if i % j == 0:
flag = False
break
else:
flag = True
if flag:
arr.append(i)

print(len(arr), arr)

# exercise_12()


posted @ 2020-07-13 18:29  _Roki  阅读(55)  评论(0编辑  收藏