简体   繁体   English

"我不明白这段代码试图做什么?"

[英]I do not understand what this piece of code is trying to do?

I am new to python and my professor keeps posting this problem for the class to answer:我是 python 新手,我的教授一直在发布这个问题,让全班同学回答:

*x = 2 
 y = 3
 sum = add( x, y)
 print(sum)
 def add (num1 = 0, num2 = 0):
 total = num1 + num2
 return total**

As you correctly identified, this code is calling the function add before it's defined.正如您正确识别的那样,此代码在定义之前调用函数 add 。 Furthermore, the astrix in front of the first variable is out of place - that should make a list out of otherwise unassigned variables.此外,第一个变量前面的 astrix 不合适 - 这应该从其他未分配的变量中列出。 The double astrix on the return line is also out of place.回程线上的双星也格格不入。

The question of "What is the code trying to do?" “代码试图做什么?”的问题Is poorly phrased, but I'd wager that the answer your professor is looking for is "The code is trying to print the sum of the two given variables to the console."措辞不佳,但我敢打赌,您的教授正在寻找的答案是“代码正在尝试将两个给定变量的总和打印到控制台。”

"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM