我之前看到过这个答案,但是我在这里找不到丢失的END。这是一个用于学习的简单Ruby程序。我回去打字,完全按照他们的输入。仍然出现错误。终点在哪里?
puts "Welcome to 'Get My Number!'"
print "What's your name? "
input = gets
name = input.chomp
puts "Welcome, #{name}!"
# Store a random number for the player to guess.
puts "I've got a random number between 1 and 100."
puts "Can you guess it?"
target = rand(100) + 1
# Track how many guesses the player has made.
num_guesses = 0
# Track whether player has guessed correctly.
guessed_it = false
Until num_guesses == 10 || guessed_it
puts "You've got #{10 - num_guesses} guesses left."
print "Make a guess: "
guess = gets.to_i
num_guesses += 1
# Compare guess to target and print appropriate message.
if guess < target
puts "Oops. Your guess was LOW."
elsif guess > target
puts "Oops. Your guess was HIGH."
elsif guess == target
puts "Good job, #{name}!"
puts "You guessed my number in #{num_guesses} guesses!"
guessed_it = true
end
end
#If the player didn't guess in time, show the target number.
unless guessed_it
puts "Sorry. You didn't get my number. (It was #{target}.)"
答案 0 :(得分:2)
我认为问题出在if
和elsif
区块中。将其更改为case
。此外,它更干净,更易于理解。
例如,以这种方式:
case
when guess < target then puts "Oops. Your guess was LOW."
when guess > target then puts "Oops. Your guess was HIGH."
when guess == target then
puts "Good job, #{name}!"
puts "You guessed my number in #{num_guesses} guesses!"
guessed_it = true
end
我希望它对您有用。
答案 1 :(得分:1)
如汤姆·洛德(Tom Lord)所述,您在末尾缺少SELECT SUM(b.amount) FROM data GROUP BY a, c
,而每个Sagar Pandya关键字end
都应全部小写。您的申请全文如下。
Until