1

Sorry in advance for what I'm sure will be a very simple question to answer, I'm very new to python.

I have a project that I'm working on that takes inputs about the size of a room and cost of materials/installation and outputs costs and amount of materials needed.

I've got everything working but I can't make my dollar sign in my ouputs appear next to the outputs themselves, they always appear a space away. ($ 400.00). I know that I can add a plus sign somewhere to smush the two together but I keep getting errors when I try. I'm not exactly sure what I'm doing wrong but I would appreciate any input. I'll paste the code that works without error below. I put spaces inbetween the lines so it can be seen more clearly.

wth_room = (int(input('Enter the width of room in feet:')))

lth_room = (int(input('Enter the length of room in feet:')))

mat_cost = (float(input('Enter material cost of tile per square foot:')))

labor = (float(input('Enter labor installation cost of tile per square foot:')))

tot_tile = (float(wth_room * lth_room))

tot_mat = (float(tot_tile * mat_cost))

tot_lab = (float(labor * tot_tile))

project = (float(mat_cost + labor) * tot_tile)

print('Square feet of tile needed:', tot_tile, 'sqaure feet')

print('Material cost of the project: $', tot_mat)

print('Labor cost of the project: $', tot_lab)

print('Total cost of the project: $', project)
deadshot
  • 8,881
  • 4
  • 20
  • 39

5 Answers5

2

You can change the separator to the empty string (the default is a space).

print('Material cost of the project: $', tot_mat, sep='')

print('Labor cost of the project: $', tot_lab, sep='')

print('Total cost of the project: $', project, sep='')
Jasmijn
  • 9,370
  • 2
  • 29
  • 43
1

Replace , with + because , leaves a space by default, for example:

print('Material cost of the project: $' + tot_mat)

print('Labor cost of the project: $' + tot_lab)

print('Total cost of the project: $' + project)

You can also use f-strings as so:

print(f'Material cost of the project: ${tot_mat}')

print(f'Labor cost of the project: ${tot_lab}')

print(f'Total cost of the project: ${project}')
creed
  • 1,409
  • 1
  • 9
  • 18
1

You could try using fstring syntax as well (Assuming you're using Python 3)

print(f'Material cost of the project: ${tot_mat}')
Nathan
  • 342
  • 2
  • 11
1

Use below :

print('Total cost of the project: $'+str(project))

Note: I have converted project into string with str function as it’s float . You can use same for all.

rahul rai
  • 2,260
  • 1
  • 7
  • 17
1

In addition to other answers, also note that your code will crash if someone inputs something that is in any way incorrect (e. g. "3,9" will throw an error if you try to parse it as a float). Consider reading about try/except, catching and handling error in context of the input() function.

qalis
  • 1,314
  • 1
  • 16
  • 44