python代码week1
for 循环
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 1 #Author:Zoe 2 2 #for i in range(0,3,2): 3 3 ''' 4 4 for i in range(0,10): 5 5 if i<3: 6 6 print("loop",i) 7 7 else: 8 8 continue 9 9 print("yeah...") 10 10 ''' 11 11 #continue 跳出当前本次循环 进入到下一次 12 12 #break 是结束当前循环 13 13 for i in range(10): 14 14 print('--------',i) 15 15 for j in range(10): 16 16 print(j) 17 17 if j>5: 18 18 break
while 循环
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #Author:Zoe 2 count = 1 3 while True: 4 print("count:",count) 5 count = count + 1 6 if count == 1000: 7 break
输入密码不显示:(getpass)
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #Author:Zoe 2 import getpass 3 username = input("username:") 4 #password = getpass.getpass("password:") 5 password = input("password:") 6 _username = "Zoe" 7 _password = "123456" 8 if _username ==username and _password == password: 9 print("Welcome user {name} login...".format(name=username)) 10 else: 11 print("Invalid username or password!")
条件判断if语句:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 age = input('your age is:') 2 s=int(age) 3 if s >= 18: 4 print('adult') 5 elif s >= 6: 6 print('teenager') 7 else: 8 print('kid')
小游戏1:womenheroes(未完成有问题待解决)
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 ''' 2 women heroes 0.1 version 3 Zoe 4 2017.10.01 5 ''' 6 hp = 100 7 print('Welcome To Women Heroes World') 8 print('66666666666666666666666666666') 9 userName = input('please input a userName:') 10 if not userName: 11 userName = 'player1' 12 password = input('please input your password:') 13 roleName = input('please input a roleName:') 14 roleCategory= input('please input a roleCategory:') 15 if not password: 16 password = '123456' 17 usermessage = [userName,password,roleName,roleCategory,hp] 18 print("your women hero's is :",usermessage[0] ) 19 print('your password is :',usermessage[1] ) 20 print(' roleName is :',usermessage[2] ) 21 print(' roleCategory is :',usermessage[3] ) 22 print(' hp is :',usermessage[4] ) 23 print("This is Women Heroes World ##### ,input 'a' go left ,input 'd' go right ") 24 userinput = input() 25 if userinput == 'a': 26 print("you are here *#### now,input 'a' go left ,input 'd' go right") 27 elif userinput == 'd': 28 print("you are here #*### now,input 'a' go left ,input 'd' go right") 29 userinput = input() 30 if userinput == 'a': 31 print("you are here *#### now,input 'a' go left ,input 'd' go right") 32 elif userinput == 'd': 33 print("you are here ##*## now,input 'a' go left ,input 'd' go right") 34 userinput = input() 35 if userinput == 'a': 36 print("you are here *#### now,input 'a' go left ,input 'd' go right") 37 elif userinput == 'd': 38 print("you are here ###*# now,input 'a' go left ,input 'd' go right") 39 userinput = input() 40 if userinput == 'a': 41 print("you are here *#### now,input 'a' go left ,input 'd' go right") 42 elif userinput == 'd': 43 print("you are here ####* now,input 'a' go left ,input 'd' go right")
小游戏2:guess age_of_wangheran
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #Author:Zoe 2 age_of_wangheran = 23 3 count = 0 4 #while count>3: 5 while True: 6 if count ==3: 7 print("okay, see you next time") 8 break 9 guess_age = int(input("guess age:")) 10 if guess_age == age_of_wangheran: 11 print("yes,you are right") 12 break 13 elif guess_age > age_of_wangheran: 14 print("think smaller") 15 else: 16 print("think bigger") 17 count = count + 1 18 if count == 3: 19 continue_confirm = input("do you want to keep guessing...? ") 20 if continue_confirm !="n": 21 count = 0