【发布时间】:2020-11-17 14:15:32
【问题描述】:
以下代码包含使用函数式编程输入密码。
pw = 9999
for (i in 1:3){
pw_entered=as.numeric(readline("Please enter the password: "))
if (pw_entered==pw){
print("The door is opened. Welcome!")
break
} else {
print("Password wrong. Please re-enter the password: ")
}
print("You have exceeded the maximum limit of three times. Try Later")
}
输出是,
Please enter the password: 1
[1] "Password wrong. Please re-enter the password: "
[1] "You have exceeded the maximum limit of three times. Try Later"
Please enter the password: 2
[1] "Password wrong. Please re-enter the password: "
[1] "You have exceeded the maximum limit of three times. Try Later"
Please enter the password: 3
[1] "Password wrong. Please re-enter the password: "
[1] "You have exceeded the maximum limit of three times. Try Later"
我希望消息 You have exceeded the maximum limit of three times. Try Later 仅在第三次尝试失败后显示,而不是在第一次和第二次尝试失败后显示。
【问题讨论】: