当前位置: 移动技术网 > IT编程>脚本编程>Python > Python快速入门(2)练习题

Python快速入门(2)练习题

2019年04月19日  | 移动技术网IT编程  | 我要评论

仪表设备,lady最后的犯罪画像,八木加奈耶

# c. fix_start
# given a string s, return a string
# where all occurences of its first char have
# been changed to '*', except do not change
# the first char itself.
# e.g. 'babble' yields 'ba**le'
# assume that the string is length 1 or more.
# hint: s.replace(stra, strb) returns a version of string s
# where all instances of stra have been replaced by strb.
		def fix_start(s):
		  # +++your code here+++
		  # lab(begin solution)
		  front = s[0]
		  back = s[1:]
		  fixed_back = back.replace(front, '*')
		  return front + fixed_back


# e. not_bad
# given a string, find the first appearance of the
# substring 'not' and 'bad'. if the 'bad' follows
# the 'not', replace the whole 'not'...'bad' substring
# with 'good'.
# return the resulting string.
# so 'this dinner is not that bad!' yields:
# this dinner is good!

		def not_bad(s):
		  # +++your code here+++
		  # lab(begin solution)
		  n = s.find('not')
		  b = s.find('bad')
		  if n != -1 and b != -1 and b > n:
			s = s[:n] + 'good' + s[b+3:]
		  return s


如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网