1
製作一個包含不同星號的列表的程序,然後要求用戶輸入他們的星號,然後讓程序在移動之前檢查它是否包含在列表中上。while循環不會重複一次輸入信息
問題是它確實檢查它是否在列表中,但它不會重複。
play = True
while play:
print("Welcome to my Pseudo_Sammy program, please enter your name, star sign and then your question by typing it in and pressing the enter key, and I will give you the answer to your question")
name = input("What do they call you? ")
starsigns = ("leo", "virgo", "libra", "scorpio", "sagittarius", "capricorn", "aquarius", "pisces", "aries", "taurus", "gemini", "cancer")
starsign = str(input("What star do you come from? ")).lower()
while True:
try:
if starsign in starsigns:
break
else:
raise
except:
print("Please enter a valid star sign")
question = input("What bothers you dear? ")
如果星標是在starsigns中,你有一個休息時間,這打破了while循環,刪除休息,你也不應該拋出這樣的錯誤,但你會學習,當你走,繼續我的朋友。 –
您的代碼被錯誤地縮進。爲了在這裏提出問題,我們需要確切地看到你的縮進。您可以將代碼複製/粘貼到[編輯]框中,然後將其選中,然後按Ctrl-K使其統一縮進以進行Markdown代碼格式化。 – tripleee