Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何实现while循环python的不同结果_Python_While Loop - Fatal编程技术网

如何实现while循环python的不同结果

如何实现while循环python的不同结果,python,while-loop,Python,While Loop,问题是,当n>数据集的长度时,我想提示另一条消息,然后是“正确的登录信息,欢迎回来”。但是,如果数据集[n]=accounts2,我确实希望它提示该消息。我该怎么办?您只需在while循环中添加另一条if语句即可 n = -1 while not dataset[n] == accounts2: n = n+1 if dataset[n] == accounts2 or n > len(dataset): print('correct login information,

问题是,当n>数据集的长度时,我想提示另一条消息,然后是“正确的登录信息,欢迎回来”。但是,如果数据集[n]=accounts2,我确实希望它提示该消息。我该怎么办?

您只需在while循环中添加另一条if语句即可

n = -1
while not dataset[n] == accounts2:
   n = n+1
if dataset[n] == accounts2 or n > len(dataset):

    print('correct login information, welcome back.')

我根本不会使用
while
循环

if (n > len(dataset[n])):
    # do something
else:
    print('correct login information, welcome back.')
if all(x == accounts2 for x in dataset):
    print('correct login information')