Tag: 用户输入

Ruby中的gets.chomp()用户输入错误

所以这是我的代码。 这是非常不言自明的。 print “How old are you? ” age = gets.chomp() print “How tall are you?” height = gets.chomp() print “How much do you weigh?” weight = gets.chomp() puts “So, you’re #{age} old, #{height} tall and #{weight} heavy.” 我的代码输出如下。 $ C:/Ruby200/bin/ruby.exe ex11.rb 11 11 11 How old are you? How tall are you?How much do […]

Ruby on Rails:在同一页面上使用用户输入进行计算

所以,我遇到的问题是我认为是一个非常简单的问题。 我不知道如何访问用户输入…或者我不知道如何在rails中声明临时变量。 无论如何,实现这一目标最直接的方法是什么: Enter Group Size: Select Study Site: 4 %> Hello! Nope! 我想我需要javascript来实际使它工作,但是现在我只需要知道如何使用这些变量。 任何帮助将不胜感激。 谢谢。

向用户询问信息,而不必再问

我想要求用户输入,但我只想做一次(可能保存程序中的信息),意思是这样的: print “Enter your name (you will only need to do this once): ” name = gets.chomp str = “Hello there #{name}” #<= As long as the user has put their name in the very first # time the program was run, I want them to never have to put thier name in again 我怎样才能在Ruby程序中做到这一点? […]