【发布时间】:2020-12-18 01:49:55
【问题描述】:
如何创建三个函数?至少一个应该有一个参数,一个返回应该有至少一个返回值。
这是问题:
"在 custom.py 中添加至少三个新函数。其中至少一个函数应该在 至少一个参数,并且其中至少一个应该至少有一个返回 价值”
enter code here# custom.py
def square(x):
return x*x
def cube(x):
return x*x*x
def circ(x):
return x*x*x*x
def quad(x):
return x*x*x*x*x
def sum():
return square + cube + circ + quad
----
import custom # leave off the .py
def main():
for num in range(25):
print(num, end="\t")
print(custom.square(num), end="\t")
print(custom.cube(num), end="\t")
print(custom.circ(num), end="\t")
print(custom.quad(num))
print(custom.sum)
xmas= int(input("How many presents do you want? "))
if xmas >10:
print("You crazy!")
elif xmas <10:
print("That's not bad..")
print("Done")
main()
-----
Output
0 0 0 0 0
<function sum at 0x7fc9f7aab430>
1 1 1 1 1
<function sum at 0x7fc9f7aab430>
2 4 8 16 32
<function sum at 0x7fc9f7aab430>
3 9 27 81 243
<function sum at 0x7fc9f7aab430>
4 16 64 256 1024
<function sum at 0x7fc9f7aab430>
5 25 125 625 3125
<function sum at 0x7fc9f7aab430>
6 36 216 1296 7776
<function sum at 0x7fc9f7aab430>
7 49 343 2401 16807
<function sum at 0x7fc9f7aab430>
8 64 512 4096 32768
<function sum at 0x7fc9f7aab430>
9 81 729 6561 59049
<function sum at 0x7fc9f7aab430>
10 100 1000 10000 100000
<function sum at 0x7fc9f7aab430>
11 121 1331 14641 161051
<function sum at 0x7fc9f7aab430>
12 144 1728 20736 248832
<function sum at 0x7fc9f7aab430>
13 169 2197 28561 371293
<function sum at 0x7fc9f7aab430>
14 196 2744 38416 537824
<function sum at 0x7fc9f7aab430>
15 225 3375 50625 759375
<function sum at 0x7fc9f7aab430>
16 256 4096 65536 1048576
<function sum at 0x7fc9f7aab430>
17 289 4913 83521 1419857
<function sum at 0x7fc9f7aab430>
18 324 5832 104976 1889568
<function sum at 0x7fc9f7aab430>
19 361 6859 130321 2476099
<function sum at 0x7fc9f7aab430>
20 400 8000 160000 3200000
<function sum at 0x7fc9f7aab430>
21 441 9261 194481 4084101
<function sum at 0x7fc9f7aab430>
22 484 10648 234256 5153632
<function sum at 0x7fc9f7aab430>
23 529 12167 279841 6436343
<function sum at 0x7fc9f7aab430>
24 576 13824 331776 7962624
<function sum at 0x7fc9f7aab430>
How many presents do you want? 10
Done
>>>
【问题讨论】:
-
你没有打电话给
sum。添加括号以实际执行它:print(custom.sum())
标签: python function parameters