gpt4 book ai didi

python - 我如何在Python中使用if/elif创建一个while循环而又没有语法错误

转载 作者:行者123 更新时间:2023-12-03 08:20:00 24 4
gpt4 key购买 nike

我正在尝试创建一个具有三个选项的应用程序。

如果用户选择1,则popchange将运行,
如果用户选择2,则住房将运行,我需要该应用程序继续运行,直到用户选择3并退出该应用程序。

我的代码在下面,但是它不断返回语法错误,我不知道为什么。

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

谁能告诉我为什么这会给我错误
elif choice == '3':
^
SyntaxError: invalid syntax

最佳答案

您在错误上方的行中缺少右括号。

print(housing_selected.describe())
^

关于python - 我如何在Python中使用if/elif创建一个while循环而又没有语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59038833/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com