“术语未定义”或“无效语法”或 [英] "term not defined" or "invalid syntax"

查看:102
本文介绍了“术语未定义”或“无效语法”或的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我是Python课程的第一学期计算机科学专业的学生。我们当前的分配要求我们从文件中读取列表,从文件创建二维列表,并检查2-dim列表是否构成魔术方块。 (即,添加时所有行,列和对角线彼此相等)。我们要创建几个定义,我从文件中读取,创建列表,获取第一行的总和没有问题。我需要做的下一件事是总结其他行,看看它们是否等于第一行。如果不相等,我返回false并且函数结束,如果全部相等,则返回True。当我尝试在我的areRowSumsEqualToSum中调用另一个函数(def sum(list,dimensions))时功能,我收到一条消息,告诉我术语尺寸。未定义,即使我在def sum(list,dimensions)中使用相同的术语。功能。当我尝试在定义名称中调用sum(list,dimensions)时,我得到一个无效语法。错误。


列表文件如下所示,第一行是square的尺寸,列表后面跟着一个空格。

3


8

1

6

3

5

7

4

9

2


这是我的代码,我感谢任何帮助,如果这是一团糟,我道歉。我还是绿色的。

Hello,

I am a 1st semester Computer Science student in a Python class. Our current assignment calls for us to read a list from a file, create a 2-dimensional list from the file, and check to see whether or not 2-dim list constitutes a "magic square" (i.e. all the rows, columns and diagonals equal each other when added). We are to create several definitions, and I have had no problem reading from the file, creating the list, and getting the sum of the first row. The next thing I need to do is sum up the other rows and see if they are equal to the first row. If not equal, I return a false and the function ends, if all are equal, I return a True. When I try to call another function (def sum(list, dimensions)) in my "areRowSumsEqualToSum" function, I am getting a message telling me that the term "dimensions" is not defined, even though i use the same term in the "def sum(list, dimensions)" function. When I try to call sum(list, dimensions) in the definition name, I get an "invalid syntax" error.

The list file looks like this, the first line is the dimensions of the "square", with the list following after a blank space.

3

8
1
6
3
5
7
4
9
2

Here is my code, I appreciate any help, and I apologize if this is a mess. I''m pretty green still.

展开 | 选择 | Wrap | 行号

推荐答案

我不能由于系统中的错误,请在此处引用您的代码,但这应该有所帮助:
I can''t quote your code here due to a bug in the system, but this should help:

编辑:我想缩进不会显示在这里?
edit: i guess the indents don''t show up here?



我添加了所谓的代码标签。发布或回复时,说明在右侧。


我已经标记了您的提交,但没有测试任何东西。

我不能强调这一点:评论一切。从长远来看,你会更喜欢自己,并且从别人那里获得帮助变得更容易。


玩得开心:

I''ve added what are called code tags. Instructions are on the right hand side while posting or replying.

I''ve marked up your submission, but haven''t tested any thing.
I can''t stress this enough: Comment everything. You''ll like yourself much more in the long run and getting help from others becomes easier, as well.

Have fun:

展开 | 选择 | Wrap | 行号


感谢您的回复bartonc。我现在得到这个错误:

Thanks for the reply bartonc. I now get this error:

展开 | 选择 | Wrap | 行号



您好,


我是Python课程的第一学期计算机科学专业的学生。我们当前的分配要求我们从文件中读取列表,从文件创建二维列表,并检查2-dim列表是否构成魔术方块。 (即,添加时所有行,列和对角线彼此相等)。我们要创建几个定义,我从文件中读取,创建列表,获取第一行的总和没有问题。我需要做的下一件事是总结其他行,看看它们是否等于第一行。如果不相等,我返回false并且函数结束,如果全部相等,则返回True。当我尝试在我的areRowSumsEqualToSum中调用另一个函数(def sum(list,dimensions))时功能,我收到一条消息,告诉我术语尺寸。未定义,即使我在def sum(list,dimensions)中使用相同的术语。功能。当我尝试在定义名称中调用sum(list,dimensions)时,我得到一个无效语法。错误。


列表文件如下所示,第一行是square的尺寸,列表后面跟着一个空格。

3


8

1

6

3

5

7

4

9

2


这是我的代码,我感谢任何帮助,如果这是一团糟,我道歉。我还是绿色的。

Hello,

I am a 1st semester Computer Science student in a Python class. Our current assignment calls for us to read a list from a file, create a 2-dimensional list from the file, and check to see whether or not 2-dim list constitutes a "magic square" (i.e. all the rows, columns and diagonals equal each other when added). We are to create several definitions, and I have had no problem reading from the file, creating the list, and getting the sum of the first row. The next thing I need to do is sum up the other rows and see if they are equal to the first row. If not equal, I return a false and the function ends, if all are equal, I return a True. When I try to call another function (def sum(list, dimensions)) in my "areRowSumsEqualToSum" function, I am getting a message telling me that the term "dimensions" is not defined, even though i use the same term in the "def sum(list, dimensions)" function. When I try to call sum(list, dimensions) in the definition name, I get an "invalid syntax" error.

The list file looks like this, the first line is the dimensions of the "square", with the list following after a blank space.

3

8
1
6
3
5
7
4
9
2

Here is my code, I appreciate any help, and I apologize if this is a mess. I''m pretty green still.

展开 | 选择 | Wrap | 行号


这篇关于“术语未定义”或“无效语法”或的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆