Guess the age to play
##!/usr/bin/python3#-*- coding:utf-8 -*-age = 24counter = 0for i in range: print ('-->counter: ', counter) if counter < 3: num = int (Input ("QINGSHURU&NBSP;:")) if num == age: print ("huanying") break elif num > age: print ("Tai da ") else: print ("Tai xiao") else: continue_num= input ("Ni xiang jixu ma: ") if continue_num == ' Y ': counter = 0 Continue else: print (" Bye ") break counter = Counter + 1
Login
#!/usr/bin/python3#-*-coding:utf-8-*-import getpassfor i in range (3): if I < 3:user = input ("Please enter user name:") passwor D = Getpass.getpass ("Please enter password:") if user = = "Chenhao" and Password = = "Chen": Print ("Welcome") Break Else:print ( "User name or password error") Else:print ("Too many inputs")
String formatted output
| 1234 |
name ="alex"print"i am %s "% name #输出: i am alex |
PS: string is%s; integer%d; floating-point number%f
String Common functions:
Remove whitespace
Segmentation
Length
Index
Slice
#!/usr/bin/env python# -*- coding: utf-8 -*- importsysprint(sys.argv)#输出$ python test.py helo world[‘test.py‘, ‘helo‘, ‘world‘] #把执行脚本时传递的参数获取到了 |
Os
| 123456 |
#!/usr/bin/env python# -*- coding: utf-8 -*-importos os.system("df -h") #调用系统命令 |
A complete combination.
| 123 |
importos,sysos.system(‘‘.join(sys.argv[1:])) #把用户的输入的参数当作一条命令交给os.system来执行 |
This article is from "Hao son of ▁ Yun's finger licking" blog, please be sure to keep this source http://chenhao6.blog.51cto.com/6228054/1863837
Python Learning Note 1