Python process processing
1. Process processing If...else
#!/bin/bash/env python#_*_ coding:utf-8 _*_#python version:p ython3.6import GETPASSN1 = "abc" p1 = "123" name = input ("Input Your name: ") passwd = Getpass.getpass (" Input your passwd: ") if name = = N1 and passwd = = P1:print (" Welecome login! ") Else:print ("User or pass is incorrect")
2. Process processing If...elif...elif...else
#!/bin/bash/env python#_*_ coding:utf-8 _*_#python version:3.6n1 = 21name = Int (input ("Please input ' the number which you w Ant to: ")) if name = = N1:print (" You Are too smart! ") Elif Name < 21:print ("is too small!") Else:print ("It is too big!")
3.for Cycle
Example 1:# Loop 10 Number i = 1for i in range: print (i) Example 2: #猜年龄优化for ... break# can enter 10 opportunities, enter the correct exit. N1 = 21for i in range: name = Int (input ("Please input the number which your want to:")) if name = = N1:pri NT ("You are too smart!") Break Elif Name < 21:print ("is too small!") Else:print ("It is too big!")
4.while Cycle
#!/bin/bash/env python#_*_ coding:utf-8 _*_#python version:3.6 Example # loop number, when loop 10 exits count = 0# Set counter While true: print ("Print:" ,count) count +=1 if count == 10: print ("loop completed") break; #跳出循环例2 # Guess age game, you can enter 10 times, but the wrong 3 times to exit. N1 = 21count = 0while true: if count < 3: name = int (Input ("please input the Number which you want to: ")) if name == n1: print ("You are too smart! ") &nbsP;&NBSP;&NBSP;&NBSP;BREAK;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;ELIF&NBSP;NAME&NBSP;<&NBSP;21: print ("is too small!") else: print ("it is too big!") else: print ("You are too failed! ") break; count += 1
This article is from the "506554897" blog, please be sure to keep this source http://506554897.blog.51cto.com/2823970/1906437
Python process processing