简体   繁体   English

使用函数传递参数

[英]parameter passing using functions

Is this a valid example of using functions to parameter pass and output the square of a number?这是使用函数传递参数和 output 数字平方的有效示例吗?

num = int(input('Enter a number: '))


def squared():
    num2 = num ** 2
    print(num2)


squared()

Your squared function should accept a num argument, and return the result.您的squared function 应该接受一个num参数,并返回结果。

Something like this:像这样的东西:

num = int(input('Enter a number: '))

def squared(num):
    return num ** 2

print(squared(num))

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

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