0

This is some of my python code:

my_fancy_variable = input('Choose a color to paint the wall:\n') 

if my_fancy_variable == 'red':
    print(('Cost of purchasing red paint:\n$'),math.ceil(paint_needed) * 35)
elif my_fancy_variable == 'blue':
    print(('Cost of purchasing blue paint:\n$'),math.ceil(paint_needed) * 25)
elif my_fancy_variable == 'green':
    print(('Cost of purchasing green paint:\n$'),math.ceil(paint_needed) * 23)

I am just trying to get rid of the space between the "$" and "105.

There's more code but basically I'll get a result of: Cost of purchasing red paint: $ 105

Thanks!

jfra3191
  • 59
  • 1
  • 7

2 Answers2

1

The print function has a default argument, sep, which is the separator between each argument given to the print function.

By default, it is set to a space. You can easily change it, (to nothing in your case) like so:

print('Cost of paint: $', math.ceil(paint_needed), sep='')
# Cost of paint: $150

If you wanted to separate each argument with a newline character, you could do this:

print('Cost of paint: $', math.ceil(paint_needed), sep='\n')
# Cost of paint: $
# 150

sep can be any string value you need (or want) it to be.

Remolten
  • 2,614
  • 2
  • 25
  • 29
0

I would use format strings for legibility:

f"Cost of purchasing blue paint: ${math.ceil(paint_needed) * 25}"

Another point here is how many ifs are you going to add? Indigo / orange etc.

colours = {
   'red': "$35",
   'blue': "$25",
   'green': "$23"
}

cost = colours.get(my_fancy_variable, "Unknown cost")

print(f"Cost of purchasing {my_fancy_variable} is {cost}")
Matt
  • 501
  • 3
  • 13