Commit 9c4d31b5 by BellCodeEditor

auto save

parent 672fdc3d
Showing with 11 additions and 11 deletions
#定义一个函数sum_numbers() '''
#要求这个函数能接收一个名为num的整型参数 定义一个函数sum_numbers()
#要求这个函数能计算1+2+3+……+num的结果 要求这个函数能接收一个名为num的整型参数
要求这个函数能计算1+2+3+……+num的结果
'''
d = int(input("请输入正方形的边长:"))
def sum_numbers(num): C = 4 * d #正方形周长
if num == 1: S = d * d #正方形面积
return 1
sum = num + sum_numbers(num-1)
return sum
result = sum_numbers(3) print("正方形的周长为:",C)
print(result) print("正方形的面积为:",S)
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment