LEARNING RUBY: PART 3 | VARIABLES!

Welcome brothers and sisters, today's post will be short but effective. Why short? Simple because it's easy. Now lets move on and do some explanations!

VARIABLES

The answer is in the question right? Variables simply means random values. They are simply used to store any type of value in it like integers, floats and strings. If you have seen the posts from the defalt, you know what it means. Same as in python we only have to set the value and we don't have to declare it. Now start your text editor, and type the code like this:

#This is another ruby training script. Does nothing horrible.

# These are the number of cars available to us.
cars = 100

# This is space in one car, although we've used floating numbers but, we can use integers as well.
spaceina_car = 4.0
drivers = 30
passengers = 90
carsnotdriven = cars - drivers
cars_driven = drivers
carpoolcapacity = carsdriven (*) spaceina_car
averagepassengerspercar =passengers / carsdriven

puts "There are #{cars} cars available."
puts "There are only #{drivers} drivers available."
puts "There will be #{carsnotdriven} empty cars today."
puts "We can transport #{carpool_capacity} people today."
puts "We have #{passengers} to carpool today"
puts "We need to put about #{averagepassengersper_car} in each car."

And your screen will look something like this except for text editor, I prefer nano. Did you remember in part 0, I'll be doing mistakes by myself so there are some errors in it, try to find out and tell me the comment section.

If you have done last drill,then you know what #{} means.

Please note in the line 12, I've written carpoolcapacity = carsdriven (*) spaceina_car. You are not supposed to write the mathematical function inside the parenthesis (). See the picture for more info. Well that's all for today.

STUDY DRILL

If you are following these study drills, then here is one more for you.

  1. Check out on the internet for some more usage of variables.
  2. And modify your code to use them.

That's it.

FEEDBACK

If you have any issues regarding this, you can either contact me or you can simply type your queries in the comment section. And for the future updates, I'll definitely be posting some of my codes that you can use. They may not look so cool but are very effective. Thank you all I'm:

>>>DUSTY WORLD///

Be the First to Respond

Share Your Thoughts

  • Hot
  • Active