鱼C论坛

 找回密码
 立即注册
查看: 1523|回复: 4

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

[复制链接]
发表于 2020-8-26 21:22:30 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
可以运行的
# 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.")


                               
登录/注册后可看大图

# 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
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2020-8-26 21:31:35 | 显示全部楼层
有个变量没有定义(你找找这个变量名出现的地方有没有问题),
建议你把这个英文注释翻译一下,很影响阅读的
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-8-26 22:05:51 From FishC Mobile | 显示全部楼层
下次把源代码放上来。。。
盲猜你把subtotal敲成subtoal
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-8-27 09:31:42 | 显示全部楼层

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

如何正确的发代码:https://fishc.com.cn/thread-52272-1-1.html
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-8-27 09:48:10 | 显示全部楼层
第14行的subtoal应该是敲错了,应该是subtotal
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-1-11 05:37

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表