How do to print two zero's 00 as an integer?

前端 未结 4 1412
萌比男神i
萌比男神i 2021-01-14 01:49

I\'m working on some app academy practice questions and I can\'t seem to print two 00\'s for my time conversion. Here\'s what I have so far:

def time_convers         


        
4条回答
  •  失恋的感觉
    2021-01-14 02:29

    A very simple re-structuring of your code could be with one single line in your function def -

    return "#{m/60}:#{m%60 == 0 ? '00' : m%60}"
    

    Sample execution from irb -

    2.1.5 :077 > m=100
     => 100 
    2.1.5 :078 > puts "#{m/60}:#{m%60 == 0 ? '00' : m%60}"
    1:40
     => nil 
    2.1.5 :079 > m=120
     => 120 
    2.1.5 :080 > puts "#{m/60}:#{m%60 == 0 ? '00' : m%60}"
    2:00
     => nil 
    2.1.5 :081 >
    

提交回复
热议问题