Day8: Task : Review

# String Task:

v='5+6'
v1,v2 = v.split('+')
v1 = int(v1)
v2 = int(v2)
v3 = v1 + v2
print(v3)
template = "{a}like to {b} at{c}"
v1 = input('>>>person:')
v2 = input('>>>thing:')
v3 = input('>>>where:')
m = template.format(v1,v2,v3)
print(m)
s = ''
while True:
v1 = input('usename:')
v2 = input('email:')
v3 = input('password:')
template = "{0}\t{1}\t{2}\n"
v = template.format(v1,v2,v3)
s = s + v
# if v1 = 'q'
break
print(s.expandtabs(20))

# Task files processing:

 

# 1:
def func(start,end):
sum = 0
j = 0
for i in range(start,end):
if i%3 == 0 and i%7 ==0:
j += 1
sum += i
# break
return j,sum
print(func(10,100))
# 2:
name = 'zxver'
def name():
print(id(name))
print(id(name))
name()
# 3:set
l1 = [11,22,33]
l2 = [22,33,44]
print(set(l1) & set(l2))
# 9:
def count(char):
char_list = list(char)
a = 0
b = 0
c = 0
for char in char_list:
if char.isdigit():
a += 1
elif char.isalpha():
if char.islower():
b += 1
elif char.isupper():
c += 1
print('%d,%d,%d' %(a,b,c))
count('aleAs15728')
# 33:
def func(x,y=0):
y += 1
if y == 5:
return x+y
x += y
func(x,y)
# dind't execute
x += y
return x
num = 1
result = func(num)
print(num)
print(result)
# 34:1)
def func(x,y=1):
if x == 8:
return y
y = y * x
x += 1
ret = func(x,y)
return ret
ret = func(1)
print(ret)
# 34:2)
def func(x,y=1):
if x == 1:
return y
y = y * x
x -= 1
ret = func(x,y)
return ret
ret = func(7)
print(ret)
# 34:3)
from functools import reduce
print(reduce(lambda x,y:x*y,[x for x in range(1,8)]))
# 34:4)
def func(n):
if n == 1:
return 1
return n * func(n-1)
print(func(7))
# 35:Monkey eat peaches
s = 1
func = lambda x:(x+1)*2
for i in range(9):
s = func(s)
print(s)
上一篇:敏捷开发:代码Review


下一篇:Pornhub---The 2019 Year in Review