Python3基礎之(二十)input輸入
阿新 • • 發佈:2018-11-17
一、input
variable=input()
表示執行後,可以在螢幕中輸入一個數字,該數字會賦值給自變數。看程式碼:
>>> a=input()
2
>>> print(a)
2
input()應用在if語句中.
在下面程式碼中,需要將input()
轉化成整型(是通過:int(inout())來實現的),因為在if
語句中自變數 a_input
對應的是整數型。輸入的內容和判斷句中對應的內容格式應該一致。
也可以將if
語句中的 定義成字串,其中區別請讀者自定寫入程式碼檢視。
a_input=int(input('please input a number:' ))#注意這裡要定義一個整數型
if a_input==1:
print('This is a good one')
elif a_input==2:
print('See you next time')
else:
print('Good luck')
""""
please input a number:1 #input 1
This is a good one
please input a number:2 #input 2
See you next time
please input a number:3 #input 3 or other number
Good luck
""" "
二、input擴充套件
用input()來判斷成績
score=int(input('Please input your score: \n'))
if score>=90:
print('Congradulation, you get an A')
elif score >=80:
print('You get a B')
elif score >=70:
print('You get a C')
elif score >=60:
print('You get a D')
else:
print('Sorry, You are failed ' )
""""
Please input your score:
100 #手動輸入
Congradulation, you get an A
""""