简体   繁体   中英

Python unable to run program

So I've been working on this program for a while and for some reason, Spyder (Anaconda) isn't being able to run the program. I'm guessing it's something stupid like a loop unclosed but I couldn't pinpoint anything and since Spyder won't even give me an error. Just fails to run the program. Here is the full program:

    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:"
   

And here is an extract from the .csv I've used:small business.csv 截图在这里 Any help is greatly appreciated!

I think there might be multiple things wrong with your code, but first I would check the following: it might be stuck in an infinite loop :)

In the beginning your code looks like:

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

Only if your input is exactly 0 , it will pass this while loop. If it is not, it will enter the while loop and perform an infinite loop there. The print method also doesn't work there because you try to execute:

print = "some text..."

This does not work (and actually replaces the builtin print method with your string) and you should replace those lines with `print("some text...").

If something is wrong with your .csv it could crash there as well but I am not able to check that, and I think you would receive an error if that was the case.

There might be more things wrong with the code (I see more possibilities for infinite loops, for example the while x in df ), but I would start with these! :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM