只是想知道是否有人知道为什么我的代码出现语法错误我是一个非常新的编码和需要hel [英] Just wondering if any one knows why my code is coming up with syntax error I am very new to coding and need hel
本文介绍了只是想知道是否有人知道为什么我的代码出现语法错误我是一个非常新的编码和需要hel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
menu_Cheap = [['1. Shark ',4.10,], ['2. Flounder',4.10,], ['3. Cod ',4.10,], ['4. Gurnet ',4.10,], ['5. kahawai ',4.10,], ['6. Trevall ',4.10,]]
menu_Deluxe = [['7. Snapper ',7.20,], ['8. Pink Salmon ',7.20,], ['9. Tuna ',7.20,], ['10.Smoked Marlin',7.20,], ['11.Clown fish ',7.20,], ['12.Surgeonfish ',7.20,]]
DELIVERY = 5
PICKUP = -1.05
MAX_FISH = 7
print('\nThese are the menu items and their prices \n')
for x in menu_Cheap:
print(x)
for y in menu_Deluxe:
print(y)
def Shark():
print("you have choosen Shark ")
def Flounder():
print("you have choosen Flounder ")
def Cod():
print("you have choosen Cod ")
def Gurnet():
print("you have choosen Gurnet ")
def Kahawai():
print("you have choosen Kahawai ")
def Trevally():
print("you have choosen Trevally ")
def Snapper():
print("you have choosen Snapper ")
def Pink_Salmon():
print("you have choosen Pink Salmon ")
def Tuna():
print("you have choosenTuna ")
def Smoked_Marlin():
print("you have choosen Smoked_Marlin ")
def Clown_Fish():
print("you have choosen Clown fish ")
def Surgeonfish():
print("you have choosen Surgeonfish ")
counter = 0
loop = int(input("\nPlease enter the total amount of fish you would like to order\n"))
while counter < loop :
try:
selection = int(input("\nPlease enter the type of fish you would like to order\n")
if selection == 1
Shark()
counter = counter + 1
elif selection == 2:
Flounder()
counter = counter + 1
elif selection == 3:
Cod()
counter = counter + 1
elif selection == 4:
Gurnet()
counter = counter + 1
elif selection == 5:
Kahawai()
counter = counter + 1
elif selection == 6:
Trevally()
counter = counter + 1
elif selection == 7:
Snapper()
counter = counter + 1
elif selection == 8:
Pink_Salmon()
counter = counter + 1
elif selection == 9:
Tuna()
counter = counter + 1
elif selection == 10:
Smoked_Marlin()
counter = counter + 1
elif selection == 11:
Clown_Fish()
counter = counter + 1
elif selection == 12:
Surgeonfish()
counter = counter + 1
else:
print("please enter a valuse between 1 and 3 ")
except ValueError:
print("No strings ")
exit
我尝试了什么:
i知道我的代码不是很有效且真的需要帮助
when我运行代码,它显示语法错误,第一个if语句在冒号
What I have tried:
i know my code is not very efficient and really need help
when i run the code it shows up syntax error for the first if statement at the colon
推荐答案
它应该如下:
It should be as follows:
while counter < loop :
try:
selection = int(input("\nPlease enter the type of fish you would like to order\n"))
if selection == 1:
Shark()
你错过了<$的右括号c $ c> selection = int 语句(我在上面添加了),以及以下 if
语句中的终止冒号。
You were missing the closing parenthesis on the selection = int
statement (which I have added above), and the terminating colon on the following if
statement.
您应该尝试在此行末尾添加一列;
You should try to put a column at the end of this line;
if selection == 1
如果不是您的错误,请在代码中添加注释以显示其中的位置错误。
[更新]
显示错误消息也是一个好主意。
if not your error, put a comment in code to show where is the error.
[Update]
Showing the error message is also a good idea.
这篇关于只是想知道是否有人知道为什么我的代码出现语法错误我是一个非常新的编码和需要hel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文