Skip to content

AlMakinah/FU1-Day-3-Files-HKilis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 

Repository files navigation

FU1-1-3-files

Exercise on reading a file in loop

Exercise 1

You need to create a new folder inside your exercise repository and name it files, then with Ruby you have to:

  1. Create a file inside that folder and name it hello.txt
  2. Print Hello 15 times in 15 different lines
  3. Close and save the file

The file should look like:

Hello
Hello
...15 times

Now double check the content of that file, if it has the right content, then here you go.

Exercise 2

You need to read the file you created in the previous exercise (hello.txt), then the file should look like:

Hello World!
Hello World!
...15 times

Exercise 3

Now what about generalizing the code so we can add whatever words to the end of each line we have in that file? So for example say you want to print your name at each of the lines, the output will be:

Hello World! Islam!
Hello World! Islam!
...15 times

Exercise 4

Now what if we need to dynamically change the number of lines, so say you want to print the lines only 4 times, then you want to re-run your code so it prints it 9 times. We need to generalize our code even more so we give how many lines we would print.

Example:

You want to print your name (Ahmed) 5 times, the output will be:

Hello World! Ahmed
Hello World! Ahmed
...5 times

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages