Python中文
首页
教程
问答
标签
搜索
登录
注册
试图从原始值中扣除值
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>所以我在下面写了一个小程序。它工作得很好,除了一个部分,我似乎无法让它工作。每次有一个或多个座位被占用/订购时,我都试图从原来的10或4个座位中扣除空位。但我看不出我能做到。除此之外,我的代码似乎工作得很好。你能检查一下我的代码并帮助我改进吗。谢谢</p> <p>例如ı'我想在普通座位的座位数扣除用户每次输入所需的座位数。如果他们需要2个座位,应该是10-2,或者如果他们需要地板座位,应该是4-2</p> <pre><code>def ticket_check(section, seats): sections = "general \n floor" general_seats = 10 floor_seats = 4 total_seats = general_seats + floor_seats print ("Available sections:",sections) section = input("Chose a section (G or F): ").capitalize() if general_seats > 0 or floor_seats > 0: if section == "G": print ("Available seats", general_seats) if general_seats > 0: general_seat_order = int(input("Choose no. of seats: ")) general_seats = general_seats - general_seat_order print ("Your seat order has been confirmed") else: print ("Sorry, no more general seats available") elif section == "F": print ("Available seats",floor_seats) if floor_seats > 0: floor_seat_order = int(input("Choose no. of seats: ")) floor_seats = floor_seats - floor_seat_order print ("Your seat order has been confirmed") else: print ("Sorry, No more floor seats available") else: print ("Sorry, Section not available") else: print ("Pre-sale seats are sold out") ticket_check("general \n floor", 14) </code></pre>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>每次调用<code>ticket_check</code>时,都会创建一个值为10的新<code>general_seats</code>变量。需要将该变量移到函数调用之外,以便在调用之间保持该变量</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
python语法错误(如果不在Z中,则在X中表示s)
4 回答
Python语法错误(无效)概率
10 回答
python语法错误*带有可选参数的args
5 回答
python语法错误2.5版有什么办法解决吗?
2 回答
Python语法错误2.7.4
3 回答
python语法错误30/09/2013
7 回答
Python语法错误E001
7 回答
Python语法错误not()op
10 回答
python语法错误outpu
6 回答
Python语法错误print len()
6 回答
python语法错误w3
3 回答
Python语法错误不是caugh
10 回答
python语法错误及yt-packag的使用
4 回答
python语法错误可以查出来!!瓦里亚布
3 回答
Python语法错误可能是缩进?
10 回答
Python语法错误和缩进
7 回答
Python语法错误在while循环中生成随机numb
2 回答
Python语法错误在哪里?
10 回答
python语法错误在尝试导入包时,但仅在远程运行时
10 回答
Python语法错误在电子邮件地址提取脚本中
3 回答