码迷,mamicode.com
首页 > 编程语言 > 详细

Python简单的用户交互

时间:2018-01-21 00:11:50      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:try   har   else   log   接受   cal   ring   pos   style   

 1 death_age = 80 
 2 
 3 name = input("your name:")
 4 
 5 #input 接受的所有数据都是字符串,即便你输入的是数字,但依然会被当成字符串来处理
 6 age = input("your age:")  
 7 
 8 print( type(age) )
 9 
10 #int integer = 整数 把字符串转成int,用int(被转的数据)
11 #str string = 字符串 把数据转成字符串用str(被转的数据)
12 print("Your name:",name)
13 #print("You can still live for ",  death_age - int(age)," years ....")
14 print("You can still live for " +  str(death_age - int(age)) +" years ....")

 

 1  age_of_princal = 56 
 2  
 3  guess_age = int(input(">>:") )
 4  
 5  if guess_age == age_of_princal:
 6      print("Yes, you got it !")
 7  elif guess_age > age_of_princal:
 8      print("try smaller..")
 9  else:
10      print("try bigger ...")

 

 1 score = int(input("score:"))
 2 
 3 if score > 90:
 4     print("A")
 5 elif score > 80:
 6     print("B")
 7 elif score > 70:
 8     print("C")
 9 elif score > 50:
10     print("D")
11 else:
12     print("You should harder !")

 

Python简单的用户交互

标签:try   har   else   log   接受   cal   ring   pos   style   

原文地址:https://www.cnblogs.com/pizer/p/8322120.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!