HELLO WORLD--一起|

kingwzun

园龄:3年6个月粉丝:111关注:0

7-2 sdut-oop-8 分数四则运算(类和对象) -- Fraction的使用

from fractions import Fraction as F
n=int(input())
for i in range(n):
a = input()
if a.find('+')!=-1:
ls = a.split('+')
print(F(ls[0]) + F(ls[1]))
elif a.find('-')!=-1:
ls = a.split('-')
print(F(ls[0]) - F(ls[1]))
elif a.find('*')!=-1:
ls = a.split('*')
print(F(ls[0]) * F(ls[1]))
else:
ls = a.split('\\')
print(F(ls[0]) / F(ls[1]))

本文作者:kingwzun

本文链接:https://www.cnblogs.com/kingwz/p/16331263.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   kingwzun  阅读(529)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起