在我的代碼,我想它,問我是否應該在結束時再次或接近問,我已經看到了你可以使用while循環,並要求繼續進行或中斷,但這些代碼似乎都不適合我。我需要爲學校項目添加一行代碼。製作一個while循環詢問重新啓動我的腳本
import random
import time
ans1="Without a doubt"
ans2="As I see it, yes"
ans3="Signs point to yes"
ans4="Better not tell you now"
ans5="Concentrate and ask again"
ans6="Don't count on it"
ans7="Very Doubtful"
ans8="My reply is no"
ans9="Reply hazy, try again"
ans10="Most Likely"
ans11="Very Doubtful"
ans12="Concentrate and ask again"
print("Welcome to my Magic 8 ball")
name=input("Please enter your name")
print ("Hi",name)
question = input("Hi, please ask me a question")
print("shaking...........")
time.sleep(1)
print("shaking...........")
time.sleep(1)
print("shaking...........")
time.sleep(1)
print("shaking...........")
time.sleep(1)
print ("My thought's lead too\n")
choice = random.randint(1,12)
if choice == 1:
answer = ans1
elif choice == ans2:
answer = ans2
elif choice == 3:
answer = ans3
elif choice == 4:
answer = ans4
elif choice == 5:
answer = ans5
elif choice == 6:
answer = ans6
elif choice == 7:
answer = ans7
elif choice == 8:
answer = ans8
elif choice == 9:
answer = ans9
elif choice == 10:
answer = 10
elif choice == 11:
answer = 11
else:
answer = ans12
print (answer)
input ("\n\nPress the ENTER key to finish")
顯示你有什麼用while循環嘗試。 – klutt