lundi 25 novembre 2019

how do I create a while loop using if/elif in python without getting a syntax error

I am trying to create an app that has three options.

If the user selects 1 then popchange will run, if the user selects 2 then housing will run, I need the app to continue to run until the user selected three and exits the app.

My code is below, but it keeps returning an error for syntax and I have no clue why.

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

print("\nWelcome to the data analysis app")

choice = ''

while choice != '3':
   print("Select the file you want to analyze: ")
   print("[1]:Enter 1 for Population Data  ")
   print("[2]: Enter 2 for Houseing Data  ")
   print("[3]: Enter 3 to Exit the application")

choice = input("\n What is your choice?")

if choice == '1':
  popchange= pd.read_csv("PopChange.csv")
  popchange_selected = popchange[["Pop Apr 1","Pop Jul 1", "Change Pop"]] 
  print("You selected PopChange")
  print(popchange_selected.describe())

elif choice == '2':
  housing=pd.read_csv("Housing.csv")
  housing_selected = housing[["AGE", "BEDRMS", "BUILT", "ROOMS", "UTILITY","WEIGHT","NUNITS" ]] 
  print("You selected Houseing")
  print(housing_selected.describe()

elif choice == '3':
  print("You selected 3.")
  print("Thanks for trying the application")

else:
  print("Invalid input, try again")

can anyone tell me why this is giving me the error

elif choice == '3':
   ^
SyntaxError: invalid syntax        

Aucun commentaire:

Enregistrer un commentaire