储备了教孩子 发表于 2020-8-26 21:22:30

为啥我连抄程序都不会,还运行不了

可以运行的
# AtlantaPizza.py – a simple pizza cost calculator

# Ask the person how many pizzas they want, get the # with eval()
number_of_pizzas = eval( input("How many pizzas do you want: ") )

# Ask for the menu cost of each pizza
cost_per_pizza = eval( input("How much does each pizza cost: ") )

# Calculate the total cost of the pizzas as our subtotal
subtotal = number_of_pizzas * cost_per_pizza

# Calculate the sales tax owed, at 8% of the subtotal
tax_rate = 0.08 # we store 8% as the decimal value 0.08
sales_tax = subtotal * tax_rate

# Add the sales tax to the subtotal for the final total
total = subtotal + sales_tax

# Show the user the total amount due, including tax
print("The total cost is $", total)
print("This includes $", subtotal, "for the pizza and")
print("$", sales_tax, "in sales tax.")

static/image/hrline/4.gif
# AtlantaPizza.py - a simple pizza cost calculator

# Ask the person how many pizzas they want, get the # with eval()
number_of_pizzas = eval( input("How many pizzas do you want: ") )

# Ask for the menu cost of each pizza
cost_per_pizza = eval( input("How much does each pizza cost: ") )

# Calculate the total cost of the pizzas as our subtotal
subtotal = number_of_pizzas * cost_per_pizza

# Calculate the sales tax owed, at 8% of the subtotal
tax_rate = 0.08 # we store 8% as the decimal value 0.08
sales_tax = subtoal * tax_rate

# Add the sales tax to the subtotal for the final total
total = subtotal + sales_tax

# Show the user the total amout due, including tax
print("The total cost is $",total)
print("This includes $", subtotal, "for the pizza and")
print("$",sales_tax, "in sales tax.")



大神们,帮我看看,错误出在哪里了,我不懂

错误提示:
How many pizzas do you want: 1
How much does each pizza cost: 1
Traceback (most recent call last):
File "D:\Program Files (x86)\python\lianxiti\chepter3\atlantapizza.py", line 14, in <module>
    sales_tax = subtoal * tax_rate
NameError: name 'subtoal' is not defined

昨非 发表于 2020-8-26 21:31:35

有个变量没有定义(你找找这个变量名出现的地方有没有问题),
建议你把这个英文注释翻译一下,很影响阅读的

倒戈卸甲 发表于 2020-8-26 22:05:51

下次把源代码放上来。。。
盲猜你把subtotal敲成subtoal

Twilight6 发表于 2020-8-27 09:31:42


发个完整代码呗,不同代码用代码块分开比较好

如何正确的发代码:https://fishc.com.cn/thread-52272-1-1.html

myheartflyhigh 发表于 2020-8-27 09:48:10

第14行的subtoal应该是敲错了,应该是subtotal
页: [1]
查看完整版本: 为啥我连抄程序都不会,还运行不了