'I try to take the data from the list and do simple calculation but it errors; error said "can only concatenate str (not "int") to str"
class bus:
def __init__(self, name):
self.seat = []
self.name = name
self.color = color
self.passenger = []
def input(self):
s = int(input("Enter the number of seat %s bus: "%(self.name)))
self.seat.append(s)
p = int(input("Enter the number of passenger in %s bus: "%(self.name)))
self.passenger.append(p)
def display(self):
print (self.name, "bus color is ", self.color," and have", self.seat, "seats","and have",self.passenger,"passenger")
def p(self, b=None):
if b is None:
self.seat = [int(i) for i in self.seat]
b = str(self.seat)
print(str(self.seat)+4)
name = input("Enter the name of bus driver:")
color = input("Enter the color of ther bus: ")
b1 = bus(name)
b1.input()
b1.display()
b1.p()
Solution 1:[1]
The error message is quite clear. You cannot concatenate a string ant an integer.
print(str(self.seat)+4)
should be:
print(str(self.seat)+str(4))
Additionally, please format your code, it's basically unreadable
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
