你好,我是一個Python初學者。我使用Python 3,並與我的代碼有問題。我做了完全一樣的,但加法和減法,它工作得很好,但當我用分割和乘法時,我得到一個錯誤。下面是代碼:Python計算器問題
import math
division = 'division'
multiplication = 'multiplication'
class calculator:
math = input('Enter division or multiplication: ')
if math == division:
x = float(input('First number: '))
y = float(input('Second number: '))
def division(x,y):
div = x/y
print(div)
division(x/y)
elif math == multiplication:
x = int(input('First number: '))
y = int(input('Second number: '))
def multiplication(x,y):
mult = x * y
print(mult)
multiplication(x * y)
else:
print('Invalid input!')
,這裏是錯誤,我得到:
Traceback (most recent call last):
File "/Users/linusekman/Desktop/test1.py", line 6, in <module>
class calculator:
File "/Users/linusekman/Desktop/test1.py", line 16, in calculator
division(x/y)
TypeError: division() missing 1 required positional argument: 'y'
什麼可問題是什麼?
爲什麼你甚至在這裏有類聲明? – user2357112