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(对于" no")它仍然重新运行程序。请帮忙。
答案 0 :(得分:0)
您的输入错误(并且应该提出ValueError
而不是给出您描述的行为。尝试
y = int(input(""))
而不是y=input(int(""))
:也就是说,将用户的(字符串)输入转换为整数y
,而不是尝试将空字符串转换为整数。