小编Diy*_*ght的帖子

我如何让两个变量在 ruby​​ 中除以?

我有我的变量,heightdistance. 它们由用户输入。我想将它们分开并将结果转换为一个新变量ratio.

print "How high are you?"
height = gets.chomp
print "How far are you from the landing strip?"
distance = gets.chomp
ratio = distance.to_f / height 
Run Code Online (Sandbox Code Playgroud)

当我尝试运行它时,它只是告诉我

`/': String can't be coerced into Float (TypeError)
Run Code Online (Sandbox Code Playgroud)

有什么帮助吗?

ruby math variables

1
推荐指数
1
解决办法
7233
查看次数

标签 统计

math ×1

ruby ×1

variables ×1