- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
在我的代码中,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 == Y
或 if [y, Y].include?(answer)
(对于 elsif 条件也类似)。
answer == y or Y
正在测试 answer
是否等于 y
的值或者是 Y
是的。 Y
的值将始终为真,因为您已将其设置为有效字符串。
关于ruby - elsif 不工作,如果输入继续放置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31971631/
我有某种 elsif 语句错误,我找不到: 我的 JSfiddle: http://jsfiddle.net/z3xV3/64/ Jquery: $('#slider1, #slider2, #sli
我基本上会在下面的 elsif 中说“if letter == (a letter contained within the array "letterbank") ===> print letter
如果表达式为空,你能解释一下在“elsif”中什么表达式使用 ruby 吗? arg = 3 if (arg == 1) puts "1" elsif (arg == 2) puts "2
我想使用三元语法编写 if...elsif 语句。我可以在此语句中再添加一次对 ARGV[1] 的检查吗? test-expression ? if-true-expression : if-fals
我一直在为使用 lex 和 yacc 的命令式语言开发一个编译器,今天我完成了语法,问题是我在网上读到每个语法都应该有一些转变/减少冲突,特别是如果它有 if/else 语句,这通常被称为悬空 if-
我有一个非常基本的XML,想编写一个Xpath查询来获取值。 这是XML: STD 1234 BA 1
我正在使用 webPack ISE v 13 使用以下代码对 Nexys 3 板进行编程,并通过在 if elsif 语句中交换语句来注意到完全不同的行为。本质上,我在板上使用了三个按钮:当按下第一个
我尝试用 Ruby 编写 snakes 程序。为了让自己更加熟悉Ruby。我通过将蛇的 X 和 Y 值保存在两个一维数组中来定义蛇的每个部分的位置,一个用于 X 值,一个用于 Y 值。 $x = [
在我的代码中,elsif 不起作用。如果我键入 "N" 或 "n",它会要求我输入密码而不是 puts,它应该这样做: puts "Would you like to access Your Soft
我有一个返回 nil 或非 nil 值的函数,我在下面的 if- 中使用它>else 子句: if condition_that_doesnt_involve_my_func # do stuff
我有以下代码: var_comparison = 5 print "Please enter a number: " my_num = Integer(gets.chomp) if my_num >
我在这里遇到一个简单的 if else 链错误,我无法弄清楚发生了什么。前几天我开始学习 ruby,我已经了解一些 java,只是想重新编写程序以更快地学习 ruby。我正在尝试计算元音和辅音
case/when 语句让我想起 Python 中的 try/catch 语句,它们相当昂贵操作。这与 Ruby 的 case/when 语句相似吗?除了可能更简洁之外,与 if/elsif Ruby
我的 HAML 代码中需要这种构造: - if something1 %div.a - elsif something2 %div.b - elsif something3 %div.c
使用 ruby 三元运算符,我们可以为简单的 if else 构造编写以下逻辑: a = true ? 'a' : 'b' #=> "a" 但是如果我想把它写成 if foo 'a' elsif
关于我需要在这个 Perl 代码中改变什么的任何想法? perl -wc 产生: elseif should be elsif at cgitelnet-mod.pl line 410. syntax
为什么这里带有 sub 的 eins else 比带有 sub 的 zwei elsif 慢? #!/usr/bin/env perl use warnings; use 5.012; use Ben
我正在用仙人掌图片制作一个游戏,但是当我执行代码时,如果它尝试在图片之间切换,它将停止并卡住在该点上,否则如果它不起作用,我也会对图片使用 bufferedimage我的代码: package
谁能帮忙解释一下以下代码的语法有什么问题: CREATE OR REPLACE FUNCTION linearly_decrement_offset(location_in text) RETURNS
在 ruby 中,伪代码之间有什么区别吗: if n > 2: do something to A end if n > 4: do something to B end if n >
我是一名优秀的程序员,十分优秀!