【问题标题】:Ruby redaction not printingRuby编辑不打印
【发布时间】:2013-04-24 20:53:20
【问题描述】:

我正在学习 Codecademy 课程以快速掌握 Ruby 的基础知识,但我在他们的修订版中遇到了障碍!锻炼。我发布了我认为应该做的伎俩,但它拒绝打印。

练习指导如下:

让我们从简单的开始:编写一个遍历单词的 .each 循环并打印出它找到的每个单词。

如果可以,请提供帮助。谢谢!这是我的代码:

puts "What is your text, bra?"
text = gets.chomp
text.downcase!

puts "What is being hidden?"
redact= gets.chomp
redact.downcase!

words = text.split(" ")
eachredact = redact.split(" ")

#loop through the words in the string
words.each do |x|
    print "#{x}" + " "
  end

【问题讨论】:

  • 没有打印。他们给我的错误是:糟糕,再试一次!看起来您没有将用户文本中的每个单词都打印到控制台。
  • 你认为这只是我的浏览器还是什么?
  • 你在哪里运行代码?
  • codecademy.com。这是一个你可以做练习和学习编码的网站。我将它用于一些 Ruby 基础知识。该网站有编码练习和练习右侧的窗口,其中显示了代码的输出。

标签: ruby each


【解决方案1】:

我运行如下:

puts "What is your text, bra?"
text = gets.chomp
text.downcase!

puts "What is being hidden?"
redact= gets.chomp
redact.downcase!

words = text.split(" ")
eachredact = redact.split(" ")

#loop through the words in the string
words.each do |x|
    print "#{x}" + " "
end

输出:

What is your text, bra?
i anm
What is being hidden?
Good
i anm

看这里:

【讨论】:

  • 我仍然遇到这个错误,但如果代码是正确的,那么我会假设这只是假设网站很时髦,我会继续进行下一个练习。根据说明和我编写的代码,它看起来是否正确?我猜这基本上就是我需要知道的
  • 是的,很奇怪。我的也打印了,但它们仍然给我一个错误:/哦,好吧,我会把它归结为一个小故障,然后继续下一个练习。感谢您抽出时间来帮助我!
猜你喜欢
  • 2016-12-27
  • 1970-01-01
  • 2020-02-16
  • 1970-01-01
  • 2023-03-31
  • 1970-01-01
  • 2011-08-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多