提问人:ain 提问时间:6/7/2023 更新时间:6/7/2023 访问量:28
为什么我的all_data函数一直循环?
why does my all_data function keep looping?
问:
import pandas as pd
df = pd.read_csv('sales_data.csv')
def main_menu():
print("Main Menu")
print("1) Return all current sales data")
print("2) ")
print("3) ")
print("4) ")
print("5) ")
print("x) Exit")
return input("Enter your choice: ")
def all_data():
return df
# main menu loop
x = main_menu()
while x in ["1", "2", "3", "4", "5", "x"]:
if x == "1":
all_sales = all_data()
print(all_sales)
当我输入“1”时,all_data函数会不停地循环打印我的数据帧。我该如何解决?
答:
0赞
locchuong
6/7/2023
#1
当你给出输入“1”时,程序会进入循环并检查条件,然后它会执行代码后,循环循环不停任何停止条件,如果你要出去什么,就要更新值。例:x = main_menu()
while
if x == "1":
if
while
x
import pandas as pd
df = pd.read_csv('sales_data.csv')
def main_menu():
print("Main Menu")
print("1) Return all current sales data")
print("2) ")
print("3) ")
print("4) ")
print("5) ")
print("x) Exit")
return input("Enter your choice: ")
def all_data():
return df
# main menu loop
x = main_menu()
while x in ["1", "2", "3", "4", "5", "x"]:
if x == "1":
all_sales = all_data()
print(all_sales)
x = main_menu()
评论
while x in ["1", "2", "3", "4", "5", "x"]