Str and int

train_mass = 22680
train_acceleration = 10
train_distance = 100

bomb_mass = 1

def get_force(mass, acceleration):
mxa = mass * acceleration
return mxa

train_force = get_force (int(train_mass), int(train_acceleration))

print (“The GE train supplies " + str(train_force) + " Newtons of force.”)

Doubts =>

In this why do I have to mention train_force as a string when actually it’s int?

just like here - “train_force = get_force (int(train_mass), int(train_acceleration))”

because + is string concatenation, this only works when all types are a string. Go ahead, remove str() and you will see you get an error

of course there are better ways to insert (integer) variable into a string, for example using .format() or f-string (python3.6+)

the int() are redundant indeed

This topic was automatically closed 18 hours after the last reply. New replies are no longer allowed.