python - 有人可以帮我调试我的 python 程序吗?

标签 python python-3.x

<分区>

所以每当我运行这个程序时,我都会收到一个语法错误,内容如下: 文件“dice.py”,第 17 行 def 骰子(骰子数量): ^ SyntaxError: 语法无效

程序如下:

# dice.py
# written for python 3.4
# by Will Jones

import os
import platform
import random

opSys = platform.system()

if opSys == "Windows":
    system.os("cls")
else:
    system.os("clear")

print("This program gives you a number based on 1 or more dice rolls\n")
diceAmount = eval(input("Enter an amount of dice to roll")

def dice(diceAmount):

    rolls = diceAmount

    while rolls > 0
        rolls = rolls - 1
        dieRoll = random.randint(0,6)
        sum = 0 + dieRoll
        print("The number is:", sum)

def main():

    pie = 4
    dice(diceAmount)
    input("Enter any key to quit")
    system.os("exit")

main()

我很想知道为什么它不让我定义一个该死的函数。呃...所以,唉,我来找你寻求帮助。

最佳答案

你少了一个括号

diceAmount = eval(input("Enter an amount of dice to roll")

应该是

diceAmount = eval(input("Enter an amount of dice to roll"))

此外,您的 while 循环中缺少一个冒号

while rolls > 0

应该是

while rolls > 0:

关于python - 有人可以帮我调试我的 python 程序吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27196671/

相关文章:

javascript - Python "print"不记录到 Forever.js 日志

Python 3 : RuntimeWarning with numpy. 电源

python - 如何在 Python 中使用 from x import y using importlib

python - 将字典传递给 OrderedDict 有什么问题?

python - 如何使用 python pandas 处理传入的实时数据

python - 计算二叉树中每个级别的节点数

python - 如何使用 Pandas 复制与列表中的日期值匹配的日期时间行

python - 我将如何分发 python 代码?

python - 在 python(pylab) 中解析这个 csv 文件并将其转换为字典

javascript - 在垂直轴谷歌图表上添加标题