I don't want Pepper to speak from 20:00 to 6:00 the next morning, so I'll create a method that outputs "NG" during that time and "OK" otherwise. Set the time when Pepper speaks to true and the time when he does not speak to false, and enter the time at the same time.
An example output is
pepper_talk(true, 5)
=>NG
pepper_talk(true, 6)
=>OK
pepper_talk(false, 5)
=>OK
pepper_talk(false, 5)
=>OK
It is such an image.
First, create a method.
def pepper_talk(talking, hour)
end
I will write the process so that it becomes an output example. I think it's a good idea to divide the time when you shouldn't speak from 0:00 to 6:00 and after 20:00.
def pepper_talk(talking, hour)
if talking && (hour < 6 || hour >= 20 )
puts "NG"
else
puts "OK"
end
end
Recommended Posts