• 此间的少年
    2018-10-26
    坚持到今天啦 go on

    作者回复: 加油💪

    
     2
  • czhang58
    2019-08-07
    请问使用fact函数为什么会报NameError: name 'fact' is not defined
    
    
  • Fergus
    2019-01-15
    # -*- coding: utf-8 -*-
    """
    Created on Mon Jan 14 16:23:52 2019


    @author: chen.huaiyu
    """
    #1 创建一个函数,用于接收用户输入的数字,并计算用户输入数字的和
    from functools import reduce

    a_list = []
    def add(x, y):
        return x+y

    try:
        while True:
            a = input('请输入数字:')
            if a == '':
                break
            else:
                a_list.append(int(a))
                print(reduce(add, a_list))        
    except Exception as e:
        print('注意:请输入数字 %s' %e)

    #2 创建一个函数,传入Ñ个整数,返回其中最大的数和最小的数
    b_list = []

    def compare(*args):
        print('最大值:%s 最小值:%s' %(max(*args), min(*args)))

    try:
        while True:
            b = input('请输入整数:')
            if b == '':
                break
            else:
                b_list.append(int)
        compare(b_list)
    except Exception:
        print('注意:请输入数字')



    #3 创建一个函数,传入一个参数N,返回ñ的阶乘
    def factorial(x):
                
            if x == 1:
                return 1
            elif x == 0:
                return 1
            else:
                return x*factorial(x-1)
            
    try:
        while True:
            c = input('请输入数字:')
            if c == '':
                break
            else:
                print(factorial(int(c)))
    except Exception as e:
        print('注意:请输入数字 %s' %e)


    ===========分割线=============
    老师好,对于第三题,解出n的阶乘,虽然写出来并测试正确了,但从一开始就在担心负数的影响,所以走了弯路,但到最后仍然有这样的疑惑,如果老师能看到,烦请解惑,多谢。
    展开

    作者回复: 负数没有阶乘啊

    
    
  • 军长吃司令
    2018-12-18
    讲得很好,收获多多
    
    
我们在线,来聊聊吧