def func7(): """ 生成一个随机数 :return: """ myprint(random.randint(0, 9)) myprint(map_s.upper()) # print(map_s.upper()[random.randint(0, 25)] + map_s.upper()[random.randint(0, 25)] + map_s.upper()[random.randint(0, 25)]) print((map_s[random.randint(0, 25)] + map_s[random.randint(0, 25)] + map_s[random.randint(0, 25)]).upper())
def func5(a, b, c): """ 输入三角形三边长度,并计算三角形的面积: :return: """ if a + b > c and a + c > b and b + c > a: s = (a + b + c) / 2 area = (s * (s - a) * (s - b) * (s - c)) ** 0.5 myprint(area) else: myprint("这不是个三角形")
def func2(): """ 通过用户输入两个数字,并计算两个数字之和: :return: """ num1 = input("请输入第一个数字:") num2 = input("请输入第二个数字:") myprint(type(num1)) myprint(type(num2)) sum = float(num1) + float(num2) print("数字{0}和{1}相加结果为{2}".format(num1, num2, sum))
def func6(a): """ 圆的面积公式为 :S=Pi * r ** 2 公式中 r 为圆的半径 :param a: :return: """ if isinstance(a, int) and a > 0 or isinstance(a, float) and a > 0: myprint(pi * a ** 2) # elif isinstance(a, float) and a > 0: # myprint(pi * a ** 2) else: myprint("你打错啦哈哈哈哈哈")
def func4(a, b, c): """ # 二次方程式 ax**2 + bx + c = 0 # a、b、c 用户提供,为实数,a ≠ 0 :param a: :param b: :param c: :return: """ d = (b ** 2) - (4 * a * c) sol1 = (-b - cmath.sqrt(d)) / (2 * a) sol2 = (-b + cmath.sqrt(d)) / (2 * a) myprint('结果为 {0} 和 {1}'.format(sol1,sol2))