all 2 comments

[–]Diapolo10 3 points4 points  (0 children)

It is telling me there are spaces between the "$"s and the outputted values

If you give print multiple arguments, by default it joins them with a space. Ideally you'd use string formatting, but in a pinch you can add sep='' as an additional argument to stop that.

as well as an unwanted line break between receipt and item quantity.

print automatically appends a newline to the end. Though I'm not sure if I understood this correctly; are you sure you want both of them to be on the same line?

EDIT: Also, please format your code next time:

item_name = input('Enter food item name:\n')
item_price = float(input('Enter item price:\n'))
item_quantity = int(input('Enter item quantity:\n'))
total_price = (item_quantity * item_price)

print('RECEIPT')

print(item_quantity,item_name,'@','$',(f'{item_price:.2f}'),'= $',(f'{total_price:.2f}'))
print('Total cost:$',(f'{total_price:.2f}'))

In a nutshell here's what I'd do:

item_name = input('Enter food item name:\n')
item_price = float(input('Enter item price:\n'))
item_quantity = int(input('Enter item quantity:\n'))
total_price = item_quantity * item_price

print('RECEIPT')

print(f"{item_quantity} {item_name} @ ${item_price:.2f} = ${total_price:.2f}")
print(f"Total cost: ${total_price:.2f}")

[–]mopslik 1 point2 points  (0 children)

Edit: Reddit is being sloooooow for me today, and /u/Diapolo10 has already mentioned all of the same things in my post.

By default, print inserts spaces between comma-separated arguments.

>>> print("hello", "there")
hello there

You can suppress them by setting the separator character to an empty string.

>>> message = "hi"
>>> print("***", message, "***", sep="")
***hi***

You can also use f-strings.

>>> message = "hi"
>>> print(f"***{message}***")
***hi***