以下所有函数均把输入写进,但其实这是大可不必甚至不好的,希望读者可以根据需要自行提取并修改。 话不多说,直接上代码,尽可能在注释中讲解
def add():
a, b = input("Please input 2 figures:").split(" ")
a, b = int(a), int(b)
result = a+b
return result
def gether():
s1 = set(input("Please input the first gether :").split(","))
s2 = set(input("please input the second gether:").split(","))
a,b,c,d=s1&s2,s1|s2,s1-s2,s1^s2
return a,b,c,d
def num_sys_trans():
num=int(input("Please input a natural number:"))
print("The decimalism of this number:",num)
print("The binary system of this number:",bin(num))
print("The octonary system of this number:", oct(num))
print("The hexadecimal of this number:", hex(num))
if __name__ == '__main__':
print("The sum of 2 natural numbers:{}".format(add()))
print("\n")
print("The intersection(∩),union(∪) difference(-) and symmetric difference(^) of 2 sets:{}".format(gether()))
print("\n")
print(num_sys_trans())
print("\n")
|