用户输入与用户交互的程序.
输入一个年龄,打印可以再活多少年.
name=input("your name:")
age=input("your age:")
print(name,age)
猜年龄
#把字符串转成int,
用int(被转的数据)#把数据转成字符串,
用str(被转的数据) death_age = 200 age = input("your age:")#input接收的所有数据均为"字符串",
即便输入的是数字,
也会被作为字符串处理.print("you can still live for", death_age - int(age), "years.")
成绩判断
age_of_men = 56
guess_age=int(input(">>:"))
if guess_age==age_of_men:
print("yes")
elif guess_age>age_of_men:
print("try samller.")
else:
print("try bigger.")
简单练习
score = int(input("score:"))
if score > 90:
print("A")
elif score > 80:
print("B")
elif score > 70:
print("C")
elif score > 60:
print("D")
elif score < 60:
print("滚")
# This program says hello and asks for my name.
print("hello world!")
print("what is your name?") #问名字
my_name = input()
print("It is good o meet you,"+my_name)
print("The length of your name is:")
print(len(my_name))
print("What is your age?") #问年龄
my_age = input()
print("you will be"+str(int(my_age)+1)+"in a year.")
来源: http://www.jianshu.com/p/2ff38f693afb