I am practicing writing programs to improve my thinking ability in programming. This time, I wrote a program that outputs today's day of the week using the "date" class.
You can use the Date class with the following description.
python
require "date"
If you want to get today's day of the week using the Date class
python
Date.today.wday
It is described as. wday is a method provided in the Date class that can get the day of the week as an integer from 0 (Sunday) to 6 (Saturday).
Using the above, output today's day of the week in sentences. I tried it as follows.
python
require "date"
day = Date.today.wday
days = ["Day","Moon","fire","water","wood","Money","soil"]
puts "today#{days[day]}It's the day of the week"
By defining the array days, the strings were stored from Sunday (0) to Saturday (6).
Recommended Posts