My code is the following:
import cgi
data = cgi.FieldStorage()
productdescription = data.getvalue('product_description')
listprice = data.getvalue('list_price')
discountpercent = data.getvalue('discount_percent')
def calc(discountpercent):
if discountpercent > 100:
raise ValueError("Percentage discount cannot exceed 100%")
elif discountpercent < 100:
percent = float(discountpercent) / 100
discount = float(listprice) * percent
return discount
else:
raise ValueError("Invalid discount type.")
total = listprice - discountpercent
print( 'Content-type:text/html\r\n\r\n' )
print( '<!DOCTYPE HTML>' )
print( '<html lang="en">' )
print( '<head>' )
print( '<meta charset="UTF-8">' )
print( '<title>Product Discount Calculator</title>' )
print( '</head>' )
print( '<body>' )
print( '<h1>Product Description:', product_description,'</h1>' )
print( '<h1>List Price:', list_price, '</h1>' )
print( '<h1>Discount:', discount_percent, '</h1>' )
print( '<h1>Subtotal:', total, '</h1>' )
print( '</body>' )
print( '</html>' )
The traceback error says:
Traceback (most recent call last):
File "<string>", line 250, in run_nodebug
File "C:\Abyss Web Server\htdocs\display_discount.py", line 18, in <module>
total = listprice - discountpercent
TypeError: unsupported operand type(s) for -: 'NoneType' and 'NoneType'
I have no idea how to get this fixed, any help would be great.