python的文件的实际使用小程序

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_27492735/article/details/78596389

直接上代码:

filename = 'pi_th_digtal.txt'

with open(filename) as fileobject:
    lines = fileobject.readlines()

pi_string =''
for line in lines:
    pi_string += line.strip()

birthday = input('Please enter your birthday :')
if birthday in pi_string:
    print('Your birthday appears in the pi_string.')
else:
    print('sorry!')

这个代码的作用是:
在前1000位的π中找到自己的出生年月日。找不到说明不在π的前1000位。

猜你喜欢

转载自blog.csdn.net/qq_27492735/article/details/78596389