coursesa课程 Python 3 programming Functions can call other functions 函数调用另一个函数

  1. Write two functions, one called addit and one called mult. addit takes one number as an input and adds 5. mult takes one number as an input, and multiplies that input by whatever is returned by addit, and then returns the result.
def addit(number):
    s = number +5
    return s
def mult(mnum):
    b = mnum * addit(mnum)   # 调用另一个函数
    return b
fhand = int(input())
print(mult(fhand))    # 给一个函数赋值即可
    

Write a function, length, that takes in a list as the input. If the length of the list is greater than or equal to 5, return “Longer than 5”. If the length is less than 5, return “Less than 5”.

def length(lst):
    if len(lst) >= 5:
        return 'Longer than 5'
    else:
        return 'Less than 5'
fhand = input('字符用空格隔开')
lst = fhand.split()
print(length(lst))

You will need to write two functions for this problem. The first function, divide that takes in any number and returns that same number divided by 2. The second function called sum should take any number, divide it by 2, and add 6. It should return this new number. You should call the divide function within the sum function. Do not worry about decimals.

def divide(dnum):
    s = dnum / 2
    return s
def sum(number):
    x = divide(number) + 6
    return x
fhand = int(input())
print(sum(fhand))
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值