Assume that a file containing a series of names ( as strings ) is named names.dat and exists on the computers disk. Design a program that displays the numbers of names that are stored in the file. ( Hint: Open the file and read every string stored on it. Each time you read a string, increment a counter variable. When you've read all the strings from the file, the counter variable will contain the number of names stored in the file.)

Recommended Answers

All 4 Replies

Hint: Open the file and read every string stored on it. Each time you read a string, increment a counter variable. When you've read all the strings from the file, the counter variable will contain the number of names stored in the file.

That sounds about right. So why don't you go ahead and do that then?

hahha, thanks alot! No that's an excercise I'm doing, but I need to know where to start... before you start sending me python links, I haven;t found those to be helpful... I'm more of a visual learner, if you can show me an example of doing this ( not solving this exact problem) but where to start that would help. Or a site that shows python examples like that. I'm teaching myself python so it's been a rough road so far...

figured it out.. thought can't test it right? cause the names.dat doesnt exist....

thought can't test it right? cause the names.dat doesnt exist....

You can just create one. Open your favorite text editor, enter a bunch of names, save as names.dat in the directory where you run your python script from.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.