20 lines of code to test whether your birthday is in "π"

Do you want to know if your birthday is in "π"? Just a few lines of code and witness your miracle! Here comes...Put the picture!

The code is written in python, 20 lines of code ♨♨ Don’t say much, just put the picture... Uh (⊙o⊙)... No, put the code...

try:
    with open("π.txt") as file:
        data = file.read()
except FileNotFoundError:
    print("文件不存在!")

else:
    data = data.strip()
    birthday = input("你的生日:")
    if len(birthday) != 4:
        print("请输入4位!")
        exit()
    if not birthday.isdecimal():
        print("请输入数字!")
        exit()

    if birthday in data:
        number = int(data.find(birthday))+1
        print("你的生日在圆周率的第%d位!" % number)

    else:
        print("很遗憾,你的生日不在圆周率的前1000000位中。")

There is not much python knowledge involved in this small project, but an external document is needed to store the "π" value. You can go to Du Niang and ask for a copy of the π value and store it in the π.txt file in the same directory of the program. Interested friends come and have a try! You can put your birthday under the number of π in the message, and see if there are apes O(∩_∩)O

 

Guess you like

Origin blog.csdn.net/qq_45807032/article/details/104806525