Problem solving Python tutorial


#1

I’m having trouble with the one where you code for the company selling loveseats. It’s " Create Purchasing Information and Receipts for Lovely Loveseats"

I get an error message on line 20 of this code. I will copy/paste what I have:

lovely_loveseat_description = “”"
Lovely Loveseat. Tufted polyester blend on wood. 32 inches high x 40 inches wide x 30 inches deep. Red or white.
“”"
lovely_loveseat_price = “254”
stylish_settee_description = “”"
Stylish Settee. Faux leather on birch. 29.50 inches high x 54.75 inches wide x 28 inches deep. Black.
“”"
stylish_settee_price = “180.50”
luxurious_lamp_descrption = “”"
Luxurious Lamp. Glass and iron. 36 inches tall. Brown with cream shade.
“”"
luxurious_lamp_price = “52.15”
sales_tax = “.088”
customer_one_total = “0”
customer_one_itemization = “”
customer_one_total += lovely_loveseat_price
customer_one_itemization += lovely_loveseat_description
luxurious_lamp_price += customer_one_total
customer_one_itemization += lovely_loveseat_description
customer_one_tax = customer_one_total * sales_tax
customer_one_total += customer_one_tax
print(“Custoner One Items:”)
print(customer_one_itemization)
print(“Customer One Total:”)
print(customer_one_total)
customer_two_total = “0”
customer_two_itemization = “”
stylish_settee_price + customer_two_total
stylish_settee_description += customer_two_itemization
luxurious_lamp_price + customer_two_total
luxurious_lamp_description += customer_two_itemization
customer_two_tax = customer_two_total * sales_tax
print(“Customer Two Items:”)
print(customer_two_itemizaiton)
print(“Customer Two Total:”)

edit: here is the error: Traceback (most recent call last):
File “script.py”, line 20, in
customer_one_tax = customer_one_total * sales_tax
TypeError: can’t multiply sequence by non-int of type ‘str’


#2

Numerics need to written without quotes.

lovely_loveseat_price = 254

Proper use of quotes on strings is important.

lovely_loveseat_description = “Lovely Loveseat. Tufted polyester blend on wood. 32 inches high x 40 inches wide x 30 inches deep. Red or white.“

Docstrings are intended for documentation of functions, not for normal string literals.


#4

Those are also numerics.

Tip for best practice…

The person who wrote this lesson obviously didn’t have a very strict teacher. A number should never be written with a leading decimal.

sales_tax = 0.088

#5

Ha, you replied before I deleted and saw that. Here is what I have now.

lovely_loveseat_description = “Lovely Loveseat. Tufted polyester blend on wood. 32 inches high x 40 inches wide x 30 inches deep. Red or white.”
lovely_loveseat_price = 254
stylish_settee_description = “Stylish Settee. Faux leather on birch. 29.50 inches high x 54.75 inches wide x 28 inches deep. Black.”
stylish_settee_price = 180.50
luxurious_lamp_descrption = “Luxurious Lamp. Glass and iron. 36 inches tall. Brown with cream shade.”
luxurious_lamp_price = 52.15
sales_tax = .088
customer_one_total = 0
customer_one_itemization = “”
customer_one_total += lovely_loveseat_price
customer_one_itemization += lovely_loveseat_description
customer_one_total += luxurious_lamp_price
customer_one_itemization += lovely_loveseat_description
customer_one_tax = customer_one_total * sales_tax
customer_one_total += customer_one_tax
print(“Custoner One Items:”)
print(customer_one_itemization)
print(“Customer One Total:”)
print(customer_one_total)
customer_two_total = 0
customer_two_itemization = “”
stylish_settee_price + customer_two_total
stylish_settee_description += customer_two_itemization
luxurious_lamp_price + customer_two_total
luxurious_lamp_description += customer_two_itemization
customer_two_tax = customer_two_total * sales_tax
print(“Customer Two Items:”)
print(customer_two_itemizaiton)
print(“Customer Two Total:”)

What I have now as an answer is closer to being correct but still has an error code for customer 2.


#6

new error code (sorry forgot to post it)

Custoner One Items:
Lovely Loveseat. Tufted polyester blend on wood. 32 inches high x 40 inches wide x 30 inches deep. Red or white.Lovely Loveseat. Tufted polyester blend on wood. 32 inches high x 40 inches wide x 30 inches deep. Red or white.
Customer One Total:
333.09119999999996
Traceback (most recent call last):
File “script.py”, line 25, in
luxurious_lamp_description += customer_two_itemization
NameError: name ‘luxurious_lamp_description’ is not defined


#7

Those lines are written in reverse.

customer_two_total += price
customer_two_itemization += item

#9

Here’s what I have now: lovely_loveseat_description = “Lovely Loveseat. Tufted polyester blend on wood. 32 inches high x 40 inches wide x 30 inches deep. Red or white.”
lovely_loveseat_price = 254
stylish_settee_description = “Stylish Settee. Faux leather on birch. 29.50 inches high x 54.75 inches wide x 28 inches deep. Black.”
stylish_settee_price = 180.50
luxurious_lamp_descrption = “Luxurious Lamp. Glass and iron. 36 inches tall. Brown with cream shade.”
luxurious_lamp_price = 52.15
sales_tax = .088
customer_one_total = 0
customer_one_itemization = “”
customer_one_total += lovely_loveseat_price
customer_one_itemization += lovely_loveseat_description
customer_one_total += luxurious_lamp_price
customer_one_itemization += lovely_loveseat_description
customer_one_tax = customer_one_total * sales_tax
customer_one_total += customer_one_tax
print(“Custoner One Items:”)
print(customer_one_itemization)
print(“Customer One Total:”)
print(customer_one_total)
customer_two_total = 0
customer_two_itemization = “”
customer_two_total += stylish_settee_price
customer_two_itemization += stylish_settee_description
customer_two_total += luxurious_lamp_price
customer_two_total
customer_two_itemization += luxurious_lamp_description
customer_two_tax = customer_two_total * sales_tax
print(“Customer Two Items:”)
print(customer_two_itemizaiton)
print(“Customer Two Total:”)

error code:

Custoner One Items:
Lovely Loveseat. Tufted polyester blend on wood. 32 inches high x 40 inches wide x 30 inches deep. Red or white.Lovely Loveseat. Tufted polyester blend on wood. 32 inches high x 40 inches wide x 30 inches deep. Red or white.
Customer One Total:
333.09119999999996
Traceback (most recent call last):
File “script.py”, line 26, in
customer_two_itemization += luxurious_lamp_description
NameError: name ‘luxurious_lamp_description’ is not defined


#10

Check the spelling of description.


#12

Figured it out and solved. Thanks so much dude!


#13

One thing you said, in particular, I’m curious about:

“Docstrings are intended for documentation of functions, not for normal string literals.”

Please elaborate the difference


#14

str => “double quotes” or ‘single quotes’

def foo(bar):
    """
    a function to operate on `bar`
    """
    print (foo.__doc__)

When a docstring appears at the top of a function it can be accessed by the internal attribute, func.__doc__. Clearly it is intended for documenting functions.

It can be used for pre-formatted text (for instance, a detailed options menu with raw_input) in special instances but should not be the go-to approach to writing string literals.


#15

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