while用法
Posted li105803859
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了while用法相关的知识,希望对你有一定的参考价值。
while count < 10: count += 1 # count = count + 1 if count == 7: print(‘ ‘) else: print(count) count = 0 while count < 10: count += 1 # count = count + 1 if count == 7: continue print(count)
循环到7输入为空
#3、输出 1-100 内的所有奇数 #方法一: # count = 1 # while count < 101: # print(count) # count += 2 #方法二: # count = 1 # while count < 101: # if count % 2 == 1: # print(count) # count += 1 #5、求1-2+3-4+5 ... 99的所有数的和 # sum = 0 # count = 1 # while count < 100: # if count % 2 == 0: # sum = sum - count # else: # sum = sum + count # count += 1 # print(sum)
6、用户登陆(三次机会重试) #input 心中有账号,密码 while i = 0 while i < 3: username = input(‘请输入账号:‘) password = int(input(‘请输入密码:‘)) if username == ‘kkkllppp‘ and password == 123: print(‘登录成功‘) else: print(‘登录失败请重新登录‘) i += 1
以上是关于while用法的主要内容,如果未能解决你的问题,请参考以下文章