gpt4 book ai didi

ruby - elsif 不工作,如果输入继续放置

转载 作者:太空宇宙 更新时间:2023-11-03 17:47:42 24 4
gpt4 key购买 nike

在我的代码中,elsif 不起作用。如果我键入 "N""n",它会要求我输入密码而不是 puts,它应该这样做:

puts "Would you like to access Your Software Wizard?"
puts "Type Y for Yes and N for No"
answer = gets.to_s
y = "yes"
n = "no"
Y = "yes"
N = "no"
if answer == y or Y
puts " Please Insert Password:"
password = gets.to_s
elsif answer == n or N
puts "Quitting..... an Alert Email and an Alert Sms has been sent to User of attempted access"
puts "Password has been changed and newly encripted"
puts "Good Bye"
end

我做错了什么?

最佳答案

if answer == y or Y 更改为 if answer == y || answer == Yif [y, Y].include?(answer)(对于 elsif 条件也类似)。

answer == y or Y 正在测试 answer 是否等于 y 的值或者是 Y 是的。 Y 的值将始终为真,因为您已将其设置为有效字符串。

关于ruby - elsif 不工作,如果输入继续放置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31971631/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com