[英]Making a Magic 8 Ball program in python, what's wrong with this?
import time
import random
import os
import sys
os.system('cls')
def randomanswer():
os.system('cls')
x = random.randint(0,7)
if x == 0:
print("""
/\\
/ \\
/ \\
/ \\
/ FOCUS \\
/ AND \\
/ TRY AGAIN \\
/______________\\""")
if x == 1:
print("""
/\\
/ \\
/ \\
/ \\
/ \\
/ YES \\
/ \\
/______________\\""")
if x == 2:
print("""
/\\
/ \\
/ \\
/ ARE \\
/ YOU \\
/ CRAZY??? \\
/ NO!!!! \\
/______________\\""")
if x == 3:
print("""
/\\
/ \\
/ \\
/ \\
/ NO \\
/ \\
/ \\
/______________\\""")
if x == 4:
print("""
/\\
/ \\
/ \\
/ \\
/ LOOKS \\
/ GOOD \\
/ \\
/______________\\""")
if x == 5:
print("""
/\\
/ \\
/ \\
/ \\
/ BETTER \\
/ NOT TELL \\
/ YOU NOW \\
/______________\\""")
if x == 6:
print("""
/\\
/ \\
/ \\
/ \\
/ YES, \\
/ \\
/ DEFINITELY \\
/______________\\""")
if x == 7:
print("""
/\\
/ \\
/ \\
/ \\
/ MAYBE \\
/ \\
/ SOMEDAY \\
/______________\\""")
y=0
print("AGAIN?")
print("""
1. YES
2. NO
""")
y = input(int(""))
if y == 1:
guess()
else:
print("")
def guess():
os.system('cls')
print("ASK ME A QUESTION")
print("")
input("")
time.sleep(1.)
print("")
print("TO SHAKE MAGIC 8 BALL PRESS ENTER")
input("")
time.sleep(2.)
randomanswer()
guess()
當我運行它時,到最后並鍵入 2(對於“否”)它無論如何都會重新運行程序。 請幫忙。
您的輸入是錯誤的(並且應該引發ValueError
而不是給出您描述的行為)。 嘗試
y = int(input(""))
而不是y=input(int(""))
:也就是說,將用戶的(字符串)輸入轉換為整數y
而不是嘗試將空字符串轉換為整數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.