[Solved] TypeError: unsupported operand type(s) for /: ‘type’ and ‘float’ [closed]


Here you just assigned the type object intto variable cost. May be you were trying to assign a data type to variable cost like we do in C, but that is not required in python.

cost = int

You asked for user input but didn’t assign the returned value to any variable, so that value is actually lost.

raw_input(‘What is the cost: ‘)

This will raise error as you’re trying to divide a type object(int) by a float.

print ‘list=”, cost /.65

A simple solution:

#get input from user, the returned value will be saved in the variable cost.
cost = raw_input("What is the cost:  ')  

# convert cost to a float as raw_input returns a string, float 
# is going to be more appropriate for money related calculations than an integer
cost_fl = float(cost)  

#use string formatting 
print 'list = {}$'.format(cost_fl /.65)

3

solved TypeError: unsupported operand type(s) for /: ‘type’ and ‘float’ [closed]