标签:
name1 = ["Alex Li"] nam2=["Alex Li"] name11 = "Alex" name22="Alex"
int_input = int(input("Plz input your number "))
input和raw_input raw_input可以接受任何格式的输入 只在python2.7里有 input会强制转换成str
user_input = input("plz input name : ") username = user_input info2 = """ info of {Username}""".format(Username=username) print (info2)
user_input = input("plz input name : ") age_input = input("Plz input age : ") username = user_input age =age_input info2 = """ info of {},age is {}""".format(age,age) print (info2)
p=[‘kzc‘,18] print (‘{0[0]},{0[1]}‘.format(p))
1 #!/usr/bin/env python 2 # -*- coding:utf-8 -*- 3 __author__ = ‘zouyi‘ 4 5 """" input """ 6 7 # user_input = input("plz input name : ") 8 # age_input = input("Plz input age : ") 9 # username = user_input 10 # age =age_input 11 # info2 = """ info of {username},age is {age}""".format(username,age) 12 # print (info2) 13 14 15 """" class """ 16 # class Person: 17 # def __init__(self,name,age): 18 # self.name,self.age = name,age 19 # def __str__(self): 20 # print ("THIS name is {},age is {}".format(self.name,self.age)) 21 22 """" listput """ 23 24 p=[‘kzc‘,18] 25 print (‘{0[0]},{0[1]}‘.format(p))
import getpass password = getpass.getpass("plz inpt your pass : ")
九、小练习(while循环猜数字项目)
这里主要是随机Radom产生一个数字,每次来采取这个数字,当持续到3次的时候询问是否继续
1 #!/usr/bin/env python 2 # -*- coding:utf-8 -*- 3 __author__ = ‘zouyi‘ 4 import random,time 5 6 num = random.randint(1,99) 7 flag = True 8 count = 0 9 10 while flag: 11 starttime = time.clock() 12 count = count +1 13 if count ==3: 14 contniue_confirm = input("Do you want continue y/n ") 15 if contniue_confirm =="y": 16 print ("ok CONTNIUE GAME..Try to guess...") 17 count=0 18 else: 19 print ("Exit..") 20 break 21 print ("your guess count : %s"%(count)) 22 try: 23 guess_input = int(input("plz input your guess (1-100): ")) 24 except Exception as e: 25 print(‘hehe..have wrong...‘) 26 else: 27 if guess_input == num: 28 print ("you got it..\n") 29 endtime = time.clock() 30 flag = False 31 print ("""spend time {} sec""".format(int(endtime-starttime))) 32 elif guess_input>num: 33 print ("think smaller\n") 34 continue 35 elif guess_input<num: 36 print("think bigger\n") 37 continue 38 elif guess_input ==str(guess_input): 39 print("Need input type int ..") 40 else: 41 "Timeout...."
标签:
原文地址:http://www.cnblogs.com/zoee/p/5700155.html