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 !")