新手一枚,刚开始学习Python,买了Python编程(从入门到实践)这本书。
目前学习到第10章《文件和异常》,然后书中10.1.6 小节,圆周率中包含你的生日吗?
filename = 'pi_million_digits.txt'
with open(filename) as file_object:
lines = file_object.readlines()
pi_string = ''
for line in lines:
pi_string += line.strip()
birthday = input("Enter your birthday, in the form mmddyy: ")
if birthday in pi_string:
print("Your birthday appears in the first million digits of pi!")
else:
print("Your birthday does not appear in the first million digits of pi.")
关于这一段,有个问题请教:
如果其中包含生日,请问如何打印出这些数字,并在其中重点显示出所包含的生日数字呢?
比如生日数字加粗、换一种颜色或多种颜色显示、或者括起来?之类的。
忘不吝赐教,谢谢。