Last active
May 12, 2018 10:02
-
-
Save manojnaidu619/452bfeb18bda51c589e7d8c668e3eacb to your computer and use it in GitHub Desktop.
A simple ruby script to Write n number of Odd or Even numbers into file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
puts "Enter 0 for even and 1 for Odd." | |
inp = gets.to_i | |
case inp | |
when 0 | |
file = File.open("file_writer.txt",'w') | |
for i in 1..1000 do # Specify the range for EVEN loop | |
file.write(i, ' ') if i.even? | |
end | |
sleep 0.5 | |
puts "EVEN numbers written into the file!!!" | |
puts 'closing file...' | |
sleep 1 | |
puts "file closed" | |
file.close | |
when 1 | |
file = File.open("file_writer.txt",'w') | |
for i in 1..1000 do # Specify the range for ODD loop | |
file.write(i, ' ') if !i.even? | |
end | |
sleep 0.5 | |
puts "ODD numbers written into the file!!!" | |
puts 'closing file...' | |
sleep 1 | |
puts "file closed" | |
file.close | |
else | |
puts "Please enter valid digit!!, try again" | |
end | |
=begin | |
HOW TO RUN: | |
1. Open terminal | |
2. type: ruby FILENAME | |
=end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment