XJTU_Python/homework/3/8.py

23 lines
821 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from math import *
# 输入的第一个数代表要选择的操作后两个数代表要计算的数x,y。第1个数为1表示加为2表示减为3表示乘为4表示除为5表示求余数为6表示乘方(x的y次方)为7表示开方(x的y次开方)为8表示求对数x以y为底的对数。x,y都为整数结果保留两位小数
a, x, y = map(int, input().split())
if (a == 1):
print("{:.2f}".format(x + y))
elif (a == 2):
print("{:.2f}".format(x - y))
elif (a == 3):
print("{:.2f}".format(x * y))
elif (a == 4):
print("{:.2f}".format(x / y))
elif (a == 5):
print("{:.2f}".format(x % y))
elif (a == 6):
print("{:.2f}".format(x**y))
elif (a == 7):
print("{:.2f}".format(x**(1 / y)))
elif (a == 8):
print("{:.2f}".format(log(x) / log(y)))
#code by Luthics