I wrote a program which checks if PI (first one million digits)
contains a person's birth year.

file_path = "C:/Users/Rafael/PythonCode/PiDigits.txt"

with open (file_path) as a:
    b = a.read()

get_year = input("What year were you born? ")

for year in b:
    if get_year in b:
        print("Your year of birth occurs in PI!")
        break
    else:
        print("Your year of birth does not occur in PI.")
        break

As a next challenge, I wanted to check how often a person's birth year
occurs in PI. Unfortunately, I wasn't able to figure out how to use
the loop count properly. Can anyone help? Thanks!

file_path = "C:/Users/Rafael/PythonCode/PiDigits.txt"
with open(file_path) as a:
    b = a.read()

get_year = input("What year were you born? ")

count = 0
for year in b:
    if get_year in b:
        count += 1
    else:
        print("Your birth date does not occur in PI.")
        break
    sum_count = sum(count)
    print("Your birth date occurs %s times in PI!" % (sum_count))
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
  • [Tutor] Count... Rafael Knuth
    • Re: [Tut... Alan Gauld via Tutor
      • Re: ... D . V . N . Sarma డి . వి . ఎన్ . శర్మ
        • ... Alan Gauld via Tutor
          • ... D . V . N . Sarma డి . వి . ఎన్ . శర్మ
            • ... Alan Gauld via Tutor
            • ... Alan Gauld via Tutor
              • ... Mats Wichmann
                • ... D . V . N . Sarma డి . వి . ఎన్ . శర్మ
                • ... Alan Gauld via Tutor
                • ... D . V . N . Sarma డి . వి . ఎన్ . శర్మ

Reply via email to