它表示'扫描字符串文字时'EOL'... 请告诉我我的代码有什么问题。
import random
r = random.Random()
Money = 10000
print("You have 10000 dollars! You can try one round using dollars. Do you want to try?)
running = True
while running:
cmd = input("Press y to try, or any key to go out.")
if cmd == y:
cmd = input("If you win, you'll get 50 dollars. Write 1 to 100, which is percentage, and amount of money you have to pay.")
num = r.randint(1,100)
if num <= cmd:
Money = Money - cmd + 60
print("JACKPOT! You've got 60 dollars, so you have ",Money," dollars now.")
else:
print("Oops, you just lost ",cmd," dollars!")
答案 0 :(得分:1)
第5行中只有一个缺少的引号:
print("You have 10000 dollars! You can try one round using dollars. Do you want to try?")
此外,在处理字符串时,你必须注意你的变量类型(即使有人输入数字,每个输入都是一个字符串)和整数,你是用于你的randoms和计算。
所以有些事情也需要修改:
if cmd == y:
必须为if cmd == 'y':
if num <= cmd:
必须为if num <= int(cmd):
print("JACKPOT! You've got 60 dollars, so you have", Money, "dollars now.")
print("Oops, you just lost", cmd, "dollars!")