[Tutor] Count for loops

Alan Gauld alan.gauld at yahoo.co.uk
Mon Apr 3 11:14:57 EDT 2017


On 03/04/17 16:07, D.V.N.Sarma డి.వి.ఎన్.శర్మ wrote:
> Modifying the code as shown below may work.

I doubt it.

> with open(file_path) as a:
>     b = a.read()
> 
> get_year = input("What year were you born? ")
> 
> count = 0
> for year in b:

Once more I ask, what does this loop do?

>     if get_year in b:
>         count += 1
> print("Your birth date occurs %s times in PI!" % (count))

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list