程序最終都是和用戶(hù)交互的,因?yàn)橛行r(shí)候我們需要從用戶(hù)哪里獲取一下信息,才能給出回應(yīng),這里就需要使用函數(shù)input()
函數(shù)input的工作原理:) 讓程序暫停運(yùn)行,等待用戶(hù)輸入一些文本。獲取用戶(hù)輸入后,Python將其存儲(chǔ)在一個(gè)變量中,方便使用。
message = input("Tell me something, and I will repeat it back to you: ")
print(message)
inpt()函數(shù)是將用戶(hù)輸入解讀為字符串,但是實(shí)際還有有數(shù)值,這時(shí)需要使用函數(shù)int()獲取用戶(hù)輸入的
number= input("how many people with you?")
number=int(number)
if number>=8:
print("no table")
else:
print("please come in")