PTA每日一题-Python-计算M和N的多个结果

用户输入两个数M和N(用两个input语句输入),其中N是整数,计算M和N的5种数学运算结果,并依次输出,结果间用空格分隔。‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬

5种数学运算分别是:‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬

M与N的和、M与N的乘积、M的N次幂、M除N的余数、M和N中较大的值

实现

#!/usr/bin/env python3
#-*- coding:utf-8 -*-
import math
from functools import reduce
#-----------------------
def returnMultipleResult(x,y):
    add=x+y
    mul=x*y
    #The result of this syntax will return a "float" data type.
    po=math.pow(x,y)
    #po=x**y
    extr=x%y
    ma=max(x,y)
    return add,mul,po,extr,ma
#main
def main():
    #i=0
    #temps=[0,0]
    a=0
    b=0
    result=(0,0,0,0,0)
    try:
        #while i<2:
           #temps[i]=float(input())
           #temps[i]=int(input())
           #i+=1
        #a=float(input())
        #b=int(input())
        a=eval(input())
        b=eval(input())
        #result=returnMultipleResult(temps[0],temps[1])
        result=returnMultipleResult(a,b)
        print(reduce(lambda x,y:x+' '+y,map(lambda x:str(int(x)),result)))
        #print(reduce(lambda x,y:x+' '+y,map(lambda x:str(round(x)),result)))
        #print(reduce(lambda x,y:x+' '+y,map(lambda x:str(x),result)))
    except Exception as e:
        print("The data's type of input is error!")
        print("Error:",e)
    except BaseException as e:
        print("The most basic exception is here:",e)
    finally:
        #test
        pass
#-------------------------
main()

输出

10
2
12 20 100 0 10
  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序员杰森

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值