2024/3/31
所花时间:1小时
代码行:70行
博客量:1篇
了解到的知识点:
def prime_factors(n):
i = 2
factors = []
while i * i <= n:
if n % i:
i += 1
else:
n //= i
factors.append(str(i))
if n > 1:
factors.append(str(n))
return factors
num = int(input())
factors = prime_factors(num)
print(",".join(factors))
def add(a, b):
return a + b
def subtract(a, b):
return a - b
def multiply(a, b):
return a * b
def divide(a, b):
if b == 0:
return "divided by zero"
return a / b
operators = {
'+': add,
'-': subtract,
'*': multiply,
'/': divide
}
num1 = float(input())
operator = input()
num2 = float(input())
if operator in operators:
result = operators[operator](num1, num2)
if isinstance(result, float):
print("{:.2f}".format(result))
else:
print(result)
else:
print("Invalid operator entered.")
def listSum(a,b):
i=0
result=0;
a=list(map(lambda x:int(x),a))
b=list(map(lambda x:int(x),b))
while i<len(a):
result+=a[i]*b[i]
i+=1
return result
def cal(a,b):
a=list(a)
b=list(b)
if a.__contains__('-'):
a.remove('-')
if b.__contains__('-'):
b.remove('-')
aLen=len(a)
bLen=len(b)
return listSum(a[-bLen:],b) if aLen>bLen else listSum(b[-aLen:],a)
def main():
s=input().split()
print(cal(s[0],s[1]))
main()