概述
problem set 1 (1)
count = 0
num = 0
while count < len(s):
if s[count] in 'aeiou':
num += 1
count += 1
print('Number of vowels: '+str(num))
problem set 1 (2) find bob (can overlapping)
num = 0
s = 'bobobo'
def find_bob(char):
if char != 'bob':
return 0
else:
return 1
for count in range (len(s)-2):
char = s[count:count+3]
num += find_bob(char)
print('Number of times bob occurs is: '+str(num))
problem set 1 (3) find 第一个 longest substring 按照字母表顺序
longest_substring = ''
s = 'abcbcd'
def find_substring(i,longest_substring):
substring = s[i]
while i < len(s)-1:
if s[i] <= s[i+1]:
substring = substring + s[i+1]
i += 1
else:
break
if len(longest_substring) >= len(substring):
return longest_substring
else:
return substring
for i in range (len(s)):
longest_substring = find_substring(i,longest_substring)
print('Longest substring in alphabetical order is: '+longest_substring)
problem set 2 (1) 还钱
pay = 10
balance = 4773
annualInterestRate = 0.2
while True:
updatebalance = balance
for i in range(11):
updatebalance = (updatebalance-pay)*(annualInterestRate/12.0+1)
if updatebalance - pay <=0:
break
else:
pay += 10
print('Lowest Payment: '+str(pay))
problem set 2 (2) 精确到小数点后2位 还钱
balance = 320000
annualInterestRate = 0.2
low = balance/12.0
monthlyrate = annualInterestRate/12.0
high = balance*(1+monthlyrate)**12/12.0
while True:
updatebalance = balance
pay = (low+high)/2
for i in range(11):
updatebalance = (updatebalance-pay)*(monthlyrate+1)
if updatebalance
- pay <=0:
if updatebalance - pay > -0.01:
break
high = pay
else:
low = pay
pay = round(pay,2)
print('Lowest Payment: '+str(pay))
最后
以上就是辛勤缘分为你收集整理的MIT 6.00.1X problem set的全部内容,希望文章能够帮你解决MIT 6.00.1X problem set所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复