[英]Python error: “break is outside the loop”
這是一個在線預訂電影票的程序。 output 顯示“break is outside the loop”。 我應該改變什么來糾正這個?
viewers = []
class TenetMovie:
def __init__(self,movie_name):
self.movie_name=movie_name
def ticket_buyer(self):
print('at any point if you want to exit press "q"')
your_name = input("your name : ")
if your_name == 'q':
break
no_of_tickets = input("how many tickets : ")
if no_of_tickets == 'q':
break
seats = input("select the seats : ")
if seats == 'q':
break
viewers.extend((self.movie_name,your_name,no_of_tickets,seats))
for viewer in viewers:
print("\nMovie : "+self.movie_name)
print("name : "+your_name)
print("Number of Tickets : "+no_of_tickets)
print("Seat Number : "+seats)
break
movie_tickets=TenetMovie(input("Which movie would you like to watch : "))
movie_tickets.ticket_buyer()
當你想退出 function 時,使用return
not break
。
您必須使用return
not break
因為您沒有使用循環,即 function。
viewers = []
class TenetMovie:
def __init__(self,movie_name):
self.movie_name=movie_name
def ticket_buyer(self):
print('at any point if you want to exit press "q"')
your_name = input("your name : ")
if your_name == 'q':
return
no_of_tickets = input("how many tickets : ")
if no_of_tickets == 'q':
return
seats = input("select the seats : ")
if seats == 'q':
return
viewers.extend((self.movie_name,your_name,no_of_tickets,seats))
for viewer in viewers:
print("\nMovie : "+self.movie_name)
print("name : "+your_name)
print("Number of Tickets : "+no_of_tickets)
print("Seat Number : "+seats)
break
movie_tickets=TenetMovie(input("Which movie would you like to watch : "))
movie_tickets.ticket_buyer()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.