class SalesGoods: def __init__(self): self.dict ={'1':'59850元','2': '76550元','3':'88940元','4':'94310元', '5':'96420元','6':'187240元','7':'142450元','8':'146540元', '9':'86160元','10':'56410元','11':'35490元','12':'51250元'} def theQuery(self): while True: print("-----" + "销售明细" + "-----") month = input("请输入需要查询的月份:") if month in self.dict: print(month + "月份销售如下:") for i in range(len(self.dict[month])): print(self.dict[month][i]) else: print("该月没有销售数据或月份输入错误") def main(self): while True: self.menu() choice = int(input("请输入选项:")) if choice == 1: self.theQuery() else: print("退出查询") break def menu(self): print("功能菜单") print("1.查询") print("0.退出") if __name__=="__main__": SalesGoods().main() 帮我修改一下,让查询的时候所有数字显示在一行
时间: 2023-11-22 19:56:31 浏览: 30
可以将输出数字的部分改为以下代码:
```
for i in range(len(self.dict[month])):
print(self.dict[month][i], end=' ')
print()
```
这样就可以将每个数字都显示在同一行了。完整修改后的代码如下:
```
class SalesGoods:
def __init__(self):
self.dict ={'1':'59850元','2': '76550元','3':'88940元','4':'94310元',
'5':'96420元','6':'187240元','7':'142450元','8':'146540元',
'9':'86160元','10':'56410元','11':'35490元','12':'51250元'}
def theQuery(self):
while True:
print("-----" + "销售明细" + "-----")
month = input("请输入需要查询的月份:")
if month in self.dict:
print(month + "月份销售如下:")
for i in range(len(self.dict[month])):
print(self.dict[month][i], end=' ')
print()
else:
print("该月没有销售数据或月份输入错误")
def main(self):
while True:
self.menu()
choice = int(input("请输入选项:"))
if choice == 1:
self.theQuery()
else:
print("退出查询")
break
def menu(self):
print("功能菜单")
print("1.查询")
print("0.退出")
if __name__=="__main__":
SalesGoods().main()
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)