day18

day18
1.编程求 s=1!+2!+3!+…..+n!
>>> n = 5
>>> s = 0
>>> t = 1
>>> for i in range(1,n+1):
... t *= i
... s ++ t
 
2.钞票换硬币 把一元钞票换成一分、二分、五分硬币(每种至少一枚),有多种换法,分 别有哪些?
>>> result = []
>>> count = 0
>>> for i in range(int(remain/1)):
... for j in range(int(remain/2)):
... for k in range(int(remain/5)):
... if(i + 2*j +k*5) == 92:
... count += 1
... result.append((i,j,k))
 
3.自己实现在一句话中查找某个单词的算法,存在返回索引号,否则返回 False
s = "you are a beautiful girl good"
def find_word(s, word):
word_len = len(word)
for i in range(len(s)):
if s[i:i+word_len] == word:
return i
return False
 
4.读入一个十进制整数,实现十进制转二进制算法将其转成二进制数 要求:不能使用现成进制转换函数,自己写代码实现
def dec_to_bin(num):
if isinstance(num, int):
result = []
while True:
temp = num % 2
num = num // 2
result.append(str(temp))
if num == 0:
break
return result[::-1]

posted @ 2019-12-24 08:18  绝世老中医  阅读(254)  评论(0编辑  收藏  举报