gpt4 book ai didi

ruby - 打印在 Ruby 中不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 18:06:05 25 4
gpt4 key购买 nike

我为类作业创建了一个非常简单的运行计算器,但我无法让它显示在一行中。我希望输出为“您的锻炼时间是 X 分钟”。我可以在一行中获得前两个部分,但是当我将“puts workout_time”替换为“print workout_time”时,它不起作用。我得到一个看起来像进度条的东西,以及“正在联系服务器”的消息。如果重要的话,我正在使用 repl.it。这是我的代码:

#warm up and cool down times are fixed
#user enters remaining values in minutes

warm_up = 4
cool_down = 4
workout_time = []

puts "How many minutes per set do you want to run?"
run = gets.chomp.to_i

puts "How many minutes do you want to rest each set?"
rest = gets.chomp.to_i

puts "How many times do you want to repeat the run/walk?"
sets = gets.chomp.to_i

workout_time << (run+rest)*sets + warm_up + cool_down

print "Your workout time will be "
puts workout_time
puts " minutes"

谢谢!

最佳答案

尝试:

print "Your workout time will be %d minutes" % [workout_time]

关于ruby - 打印在 Ruby 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45148948/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com