<center>
<table border="0">
<tr>
<td>
<figure style="margin: 0;">
<a target="_blank" href="#"><img src="https://www.wegmans.com/content/dam/wegmans/products/768/56768.jpg" height="100" width="100"></a>
</figure>
</td>
<td>
<figure style="margin:0">
<a target="_blank" href="#"><img src="https://www.wegmans.com/content/dam/wegmans/products/768/56768.jpg" height="100" width="100"></a>
</figure>
</td>
</tr>
<tr>
<td>
<figure style="margin: 0;">
<a target="_blank" href="#"><img src="https://www.wegmans.com/content/dam/wegmans/products/768/56768.jpg" height="100" width="100"></a>
</figure>
</td>
<td>
<figure style="margin:0">
<a target="_blank" href="#"><img src="https://www.wegmans.com/content/dam/wegmans/products/768/56768.jpg" height="100" width="100"></a>
</figure>
</td>
<td>
<figure style="margin: 0">
<a target="_blank" href="#"><img src="https://www.wegmans.com/content/dam/wegmans/products/768/56768.jpg" height="100" width="100"></a>
</figure>
</td>
</tr>
</table>
</center>
我的代码出了什么问题 我尝试了一切 请回答并回复我
答案 0 :(得分:2)
一些事情。
bill = price + tax + tip #You can't add up these values BEFORE calculating them
price = raw_input("What is the price of the meal") #raw_input returns a string, not a float which you will need for processing
tax = price * .06 #So here you need to do float(price) * .06
tip = price * 0.20 #And float(price) here as well.
#Then your " bill = price + tax + tip " step goes here
答案 1 :(得分:1)
首先,您不能使用尚未定义的变量:在您的代码中,您使用的是bill = price + tax + tip
,但您的程序甚至不知道价格,税金和小费是什么,所以在您询问价格并计算税金和小费之后,行应该在代码的末尾。
然后,你有raw_input
,这个函数返回一个字符串,如果你想将它转换为可以乘法的十进制数,并添加(浮点数)你可以使用price = float(raw_input("what is the price of the meal"))
纠正这两件事应该有效......
答案 2 :(得分:1)
代码中有几个问题:
raw_input
函数返回一个字符串,因此在将其强制转换为整数之前,您无法进行正确的数学计算。1.20
)的浮点数来获取账单的全部价值+ 20%。下面是一个代码片段,应该按您的需要工作,并为您提供一些思考如何将动态值传递到calculate_bill
函数中的修饰符中以获取自定义提示浮点数和自定义税浮点数:
def calculate_bill(bill, bill_modifiers):
for modifier in bill_modifiers:
bill = modifier(bill)
return bill
def calculate_tip(bill, percentage=1.20):
return bill * percentage
def calculate_tax(bill, percentage=1.06):
return bill * percentage
if __name__ == '__main__':
bill = int(input("What is the price of the meal: "))
total_bill = calculate_bill(bill, [calculate_tip, calculate_tax])
print(total_bill)