简体   繁体   中英

parameter passing using functions

Is this a valid example of using functions to parameter pass and output the square of a number?

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.

Something like this:

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

def squared(num):
    return num ** 2

print(squared(num))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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