2

所以我已经在这个程序上工作了一段时间,由于某种原因,Spyder (Anaconda) 无法运行该程序。我猜这有点像一个未闭合的循环,但我无法查明任何东西,因为 Spyder 甚至不会给我一个错误。只是无法运行程序。这是完整的程序:

    import pandas as pd
df = pd.read_csv(r"C:\Users\user\Desktop\Small_businesses1.csv",encoding='latin1')
#create start menu
def menu():
    print("Hello!, Welcome to business analysis, how may we help you?")
    print("A) Help you find a local business based on your criteria?")
    print('B) Provide you with performance analytics of businesses and industries around you?')
    print('C) To access and read an excerpt from our data file:')
    print('D) Provide you an exit from the interface')
menu()
option = str(input("Kindly enter your option here: "))    
      
while option != 0:
    if option == "A":
     print="providing you with local businesses now, please input criteria:"
df=pd.read_csv('small businesses.csv')


w=str(input('enter name here'))
df = pd.DataFrame({"name": ['Starz Café','V lounge salon','Swapnil Tyres','Game Dome','Pride Super Shopee','Lifeberries healthcare' ,'365 medical','Mad momoz','Monde Collections','Studio Hub IT','Healer Armis','Tumbledry Laundry','VCF healthclub','Max link Sports','Creamstone' ,"Archie's","Milano's café",'Café old skool','Rebellion Apprel','D.C books','Agrwal Sweets','grocers','Ronak super mart','Vision stationary']})
while (w in df):
    print(w)
    if w=='':
     break
if w!=0:
    print("Please enter a valid input from the given list")

x=str(input('enter field here'))
df = pd.DataFrame({"field": ['Food & Hospitality','Beauty, health, fitness','Automotive Repair','Sports & Recreation','General Retail','Medical Services','Medical Services (pharmacy)','Food & Hospitality','General Retail','Technology','Medical services','Cleaning and Maintance','Health, beauty and Fitness','Health, beauty and Fitness','Food & Hospitality','General Retail','Food & Hospitality','Food & Hospitality','General Retail','Stationary & Education','Food & Hospitality','General Retail','General Retail','Stationary & Education']})
while (x in df):
    print(x)
    if x=='':
     break
if x!=0:
    print("Please enter a valid input from the given list")

y=str(input('enter desired operation size here'))
df = pd.DataFrame({"operation size": ['Very small','Moderate-Large' ,'Moderate' ,'Moderate' ,'Small','Moderate' ,'Small','Moderate' ,'Small','Small','Small','Large','Moderate' ,'Moderate' ,'Moderate' ,'Large','Small','Small','Small','Small','Small','Medium','Small','Small']})
while (y in df):
    print(y)
    if y=='':
     break
if y!=0:
    print("Please enter a valid input from the given list")
    
z=str(input('enter preferred mode of service here'))
df = pd.DataFrame({"mode of service": ['Physical dine-in/Online delivery','Physical service','Physical service, Home service','Physcial service','Physical service, Home service','Physical service, Online diagnosis','Physical service','Online delivery','Physical service/remote sevice','Remote/online service','Physical service/diagnosis','Physical service/remote sevice','Physical','Physical','Physical service','Physcial service','Physcial service, Online delivery','Physical service, Online Delivery','Online delivery','Physical service, Home service','Physical service, Home service','Physical service, Home service','Physical service, Home service','Physical service, Home service']})
while (z in df):
    print(z)
    if z=='':
     break
if z!=0:
    print("Please enter a valid input from the given list")
    
if w == '':
    print (x + y + z)
if x == "":
    print(w + y + z)
elif y == "":
    print(w + x + z)
elif z == "":
    print(w + x + y)
elif x == "" and y == "":
   print(w + z)
elif x == "" and z == "":
    print(w + y)
elif y == "" and z == "":
    print(w + x)
elif w == "" and x == "":
    print(y + z)
elif w == "" and z == "":
    print(x + y)
elif w == "" and y == "":
    print(x + z)
    
    
if option == "B":
        #do option B stuff here 
        
        if option == "C" :
          import csv
          f=open('smallbusinesses.csv', 'rt')
          myReader = csv.reader(f)
          for row in myReader:
             print(row)
             
             if option == "D":
                 print("Thank you for using our interface!")
            
        menu()
        option = str(input('kindle enter your option here:'))
            

print="providing you with local businesses now, please input criteria:"
   

这是我使用的 .csv 的摘录:small business.csv 截图放在这里 非常感谢任何帮助!

4

1 回答 1

2

我认为您的代码可能有很多问题,但首先我会检查以下内容:它可能陷入无限循环:)

一开始您的代码如下所示:

while option != 0:
    if option == "A":
        print = "providing you with local businesses now, please input criteria:"  

只有当您的输入完全是0,它才会通过这个 while 循环。如果不是,它将进入while循环并在那里执行一个无限循环。print 方法在那里也不起作用,因为您尝试执行:

print = "some text..."

这不起作用(实际上print用你的字符串替换了内置方法),你应该用 `print("some text...") 替换这些行。

如果您有问题,.csv它也可能在那里崩溃,但我无法检查,如果是这种情况,我认为您会收到错误消息。

代码可能有更多问题(我看到更多无限循环的可能性,例如while x in df),但我会从这些开始!:)

于 2021-11-05T13:59:37.763 回答