In the last lesson, you learned how to open a file. Now, let's learn how to read in some data contained in the file.
To read data from a file, you can used the file_read function, that works like this:
Move the mouse over a dotted box for more information.
Now you try. Run the code and see if you can read the first line of data from the file sample.dat.
Type your code here:
See your results here:
This code will not run! Fill in the file name in the file_open line, and what will you pass in to the file_read function?
If everything works, you should see a number appear on your screen, which is the first number in the file sample.dat.
Show a friend, family member, or teacher what you've done!
Here is a share link to your code:
Does your code work? Want to run it on your iPhone?
Here's your code:
Use [Control]-[C] (Windows) or [⌘]-[C] (MacOS) to copy your code.
Paste it using [Control]-[V] (Windows) or [⌘]-[V] (MacOS) into
Then click the "Use on iPhone" button that you'll see.