Type error: not all arguments converted during string formatting when using %

164
March 25, 2022, at 8:30 PM
class car(object):
    def __init__(self, make, model,year,condition,kms):
        self.make = make
        self.model = model
        self.year = year
        self.condition = condition
        self.kms = kms
    def display(self, showAll):
        if showAll:
            print("This car is a %s %s from %s, it is %s and has $s kms." %(self.make, self.model, self.year, self.condition, self.kms))
        else:
            print("This car is a %s %s from %s." %(self.make, self.model, self.year))
whip = car('Ford', 'Fusion', 2012, 'New', 0)
whip.display(True)  #when this is false it works, when true I get the error.
Answer 1

You have $s in

print("This car is a %s %s from %s, it is %s and has $s kms." %(self.make, self.model, self.year, self.condition, self.kms))

Change it to %s

print("This car is a %s %s from %s, it is %s and has %s kms." %(self.make, self.model, self.year, self.condition, self.kms))
Rent Charter Buses Company
READ ALSO
I'm learning Python and want to remove data from a CSV file

I'm learning Python and want to remove data from a CSV file

The CSV file I'm trying to change has 2 columns

140
Conda does not create environment from yml file on MacOS

Conda does not create environment from yml file on MacOS

I'm trying to create an environment with conda after having installed Miniconda3, on macOSI am using the conda env create -f SEM1-CB

154
Gensim - index_to_key gives numbers instead of words as output

Gensim - index_to_key gives numbers instead of words as output

I'm trying to get 5 most frequent words from word2vec model created from wikipedia dumpI turned this model into KeyedVectors and the code looks like that:

180