英文:
I am working on my calculator and it can't do floats
问题
e = 'p'
def sum(a, b):
return (a + b)
def sub(a, b):
return (a - b)
def mul(a, b):
return (a * b)
def div(a, b):
return (a / b)
while True:
a = int(input('Enter 1st number: '))
b = input('Enter operator:')
c = int(input('Enter 2nd number: '))
if b == '+':
d = sum
e = 'sum'
if b == '-':
d = sub
e = 'difference'
if b == '*':
d = mul
e = 'product'
if b == '/':
d = div
e = 'quotient'
print('the ' +e+ f' of {a} and {c} is {d(a, c)}')
print('. .')
英文:
e = 'p'
def sum(a, b):
return (a + b)
def sub(a, b):
return (a - b)
def mul(a, b):
return (a * b)
def div(a, b):
return (a / b)
while True:
a = int(input('Enter 1st number: '))
b = input('Enter operator:')
c = int(input('Enter 2nd number: '))
if b == '+':
d = sum
e = 'sum'
if b == '-':
d = sub
e = 'difference'
if b == '*':
d = mul
e = 'product'
if b == '/':
d = div
e = 'quotient'
print('the ' +e+ f' of {a} and {c} is {d(a, c)}')
print('. .')
it simply can't do floats
and I need it to do floats because
I want it to do floats and integers
答案1
得分: 1
替代使用int(),您可以使用float(),它与浮点数和整数都兼容。
a = float(input('输入第一个数字: '))
b = input('输入运算符:')
c = float(input('输入第二个数字: '))
英文:
Instead of using int(), you can use float() which is compatible with both floats and integers.
a = float(input('Enter 1st number: '))
b = input('Enter operator:')
c = float(input('Enter 2nd number: '))
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论