我收到一个错误......我知道我做错了什么,但不知道如何解决它。我知道我不能将字符串添加到整数......任何想法,我将不胜感激!
self.variables['gas'] = 'gas'+add
TypeError: Can't convert 'int' object to str implicitly
我的代码:
class Cars:
def __init__(self, **kwargs):
self.variables = kwargs
def set_Variable(self, k, v):
self.variables[k] = v
def get_Variable(self, k):
return self.variables.get(k, None)
def add_gas(self, add, gas):
self.variables['gas'] = gas+add
def main():
mercedes = Cars(gas = 3)
print (mercedes.get_Variable('gas'))
print(mercedes.add_gas(4))
if __name__ == "__main__": main()