[英]new to coding and python. trying to force type (int) for a float answer
[英]*new to coding/python* I am trying to create a conversation that has a Y/N answer
我正在嘗試在 Python 中創建一小段代碼來運行對話,然后問一個是/否問題,即“你相信天空是藍色的嗎?”
當我運行代碼時,它運行良好,直到我遇到問題。 它忽略了我的 Y/N 答案參數以打印特定響應。 它給了我附加到我的“其他”聲明的打印響應。
如果我寫錯了 If/elif/else 語句,我會感到困惑嗎?
我的代碼是這樣寫的:
x = input('do you believe the sky is blue')
if x == "yes":
print("I believe you are correct")
elif x == "no":
print('I think you have a unique perspective.')
else:
print('Please answer Yes or No.)
您使用.lower()
獲取字符串的小寫版本,並且在最后一個print()
中缺少一個'
:
x = input('do you believe the sky is blue ').lower()
if x == "yes":
print("I believe you are correct")
elif x == "no":
print('I think you have a unique perspective.')
else:
print('Please answer Yes or No.')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.