Python簡單的用戶交互
阿新 • • 發佈:2018-01-21
bsp python 整數 spa 接受 score for nbsp name
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簡單的用戶交互