1
此代碼將返回基於整個字符串是否是大寫爲什麼這個「聾奶奶」程序不正確?
response = ''
while response != "BYE"
puts "What would you like deary?"
response = gets.chomp
if response = response.downcase
puts "speak up!"
else
puts "I can hear you!"
end
response = gets.chomp
end
此代碼,但是,總是返回正確的短語「說話」,無論輸入的字符串是否是全小寫或全部大寫:
puts "What would you like deary?"
response = gets.chomp
while response != "BYE"
if response = response.downcase
puts "speak up!"
else
puts "I can hear you!"
end
response = gets.chomp
end
我有點困惑,爲什麼會發生這種情況。