首页 > 代码库 > Python循环

Python循环

密码密文 passwd.py

 

import getpass

_username=‘sunny‘

password=‘000000‘

username=input("username:")

password=getpass.getpass("password:")

 

if  _username == username and _password == password :

  print("Welcome to {name} login...".format(name=username))

else :

  print("Invalid username or password")

 

guess.py

 

age = 56

count = 0

while count<4:

 

  guess_age = int(input("guess age:"))

  if guess_age == age:

    print("Congratulations !")

    break

  elif guess_age>age:

    print("ops ...")

  else:

    print("devops...")

  count +=1

  if count == 3:

    continue_flag =input("do you want to keep...")

    if continue_flag != ‘n‘

      count = 0

else:

  print("......")

 

while.py

 

count = 0

while True:

  print("count:",count)

  count +=1

 

exce1.py

for i in range(10):

/* range(0,10,2)

0~10,步长为2

*/

  print("loop:",i)

  for j in range(10):

    print(j)  

    if j>5:

      break

 

Python循环