users = {'adam' : 'Test123', 'alice' : 'Test321'}
status = ""
status = input("If you have an account, type YES, NO to create a new user, QUIT to exit: ")
while status != 'QUIT':
if status == "YES":
u_name = input("Please provide your username: ")
u_pwd = input("Please provide your password: ")
if users.get(u_name) == u_pwd:
print("Access granted!")
break
else:
print("User doesn't exist or password error! You have 2 more attempts!")
elif status == "NO":
print("\nYou're about to create a new user on my very first app. Thank you!")
new_u_name = input("Please select a name for your account!")
new_u_pwd = input("Please select a password for your account!")
users[new_u_name] = new_u_pwd
print("Thank you " + new_u_name + " for taking the risk.")
elif status == "QUIT":
print("Smart choice lol. Please come back in few months")
实现以下内容的过去方式是什么:
- 如果用户选择YES并提供有效的用户名+ pwd =访问授予退出循环(在这种情况下我使用了break
)
- 我将如何实现循环,以便在第一个else
语句之后再次要求用户输入用户名和密码,但仅用于另外2次尝试?
答案 0 :(得分:1)
我猜你可以创建一个计数器,例如:
library(lubridate)
library(dplyr)
times %>%
mutate(diff_time1 = ms(end_time) - ms(start_time)) %>%
mutate(diff_time2 = as.numeric(diff_time1)) %>%
mutate(diff_time1 = gsub("M ", "'", diff_time1)) %>%
mutate(diff_time1 = gsub("S", "\"", diff_time1))
start_time end_time diff_time1 diff_time2
1 12'10" 16'23" 4'13" 253
2 1'05" 76'20" 75'15" 4515
3 96'10" 120'22" 24'12" 1452
备注强>:
您可能还想实现以下功能:
1 - 在提示输入密码之前,检查用户名是否退出
2 - 使users = {'adam' : 'Test123', 'alice' : 'Test321'}
status = ""
status = input("If you have an account, type YES, NO to create a new user, QUIT to exit: ")
max_attempts = 2
while status != 'QUIT':
if status == "YES":
u_name = input("Please provide your username: ")
u_pwd = input("Please provide your password: ")
if users.get(u_name) == u_pwd:
print("Access granted!")
break
else:
if max_attempts > 0:
print("User doesn't exist or password error! You have {} more attempts!".format(max_attempts))
max_attempts -= 1
else:
print("Too many wrong passwords. Bye!")
break
elif status == "NO":
print("\nYou're about to create a new user on my very first app. Thank you!")
new_u_name = input("Please select a name for your account!")
new_u_pwd = input("Please select a password for your account!")
users[new_u_name] = new_u_pwd
print("Thank you " + new_u_name + " for taking the risk.")
elif status == "QUIT":
print("Smart choice lol. Please come back in few months")
和YES
案例InsEnsiTive。