我需要帮助修复“解析时出现意外的EOF错误”

时间:2022-08-26 11:58:41

I'm a first year computer science major with little clue about what I am doing, and I really need some help. I'm writing a program for an assignment that will run a simulation where the user picks 1 out of three stocks, and the program will calculate gains/losses, for 10 years.

我是第一年的计算机科学专业,对我正在做的事情一无所知,我真的需要一些帮助。我正在为一项任务编写一个程序,该程序将运行一个模拟,用户选择三个库存中的一个,该程序将计算10年的收益/损失。

Right now, i'm trying to implement the random section of the gains and losses and I keep running into unexpected eof while parsing error.

现在,我正在尝试实现收益和损失的随机部分,并在解析错误时继续遇到意外的eof。

The error disappears when I delete the last 2 lines of the code.

当我删除代码的最后两行时,错误消失。

I have searched for previous solutions to this on the website, but as I said, I'm very new to programming, and I'm not fluent enough in Python to understand the solutions posted to those questions.

我在网站上搜索过以前的解决方案,但正如我所说的,我对编程很新,而且我在Python上不够流利,无法理解发布到这些问题的解决方案。

import random


def main():
    starting_menu()
    choice_loop()

#Displays the starting menu 
def starting_menu():
    spendingCash=float(100.00)
    print("Current funds:", format(spendingCash, "0.2f"))
    print("Available investments")
    print("(1)Fly-By-Night investments (SCAMU): high risk, high potential returns")
    print("(2)Blue Chips INC (BCI): moderate risk, good yearly returns")
    print("(3)Slow and Steady Corp (BORE): mature industry, no risk but low returns")
    print("\nPlease enter a value from 1-3 only")
    print()

#Loop for if user selects a stock numbered other than 1-3
def choice_loop():
    chosen_stock=int(input("Stock Selection: "))

    while chosen_stock>3 or chosen_stock<1:
        print("Invalid choice, please enter number from 1-3 only")
        chosen_stock=int(input("Stock Selection: "))

    invest_chance=random.randrange(1,101)
    if chosen_stock==1:
        if invest_chance>=1 and invest_chance<=45:

I appreciate the help.

我很感激帮助。

1 个解决方案

#1


0  

You are getting that error because right now you have two if-statements at the bottom of your current program, without a "body" for the what should happen if the conditions of those statements are met.

您正在收到该错误,因为您现在在当前程序的底部有两个if语句,而没有“body”表示如果满足这些语句的条件会发生什么。

Python expects something after the if-statements, hence it encounters the EOF (end-of-file) when it parses your code.

Python在if语句之后需要一些东西,因此它在解析代码时会遇到EOF(文件结尾)。

What, if anything, did you have there before?

你有什么,如果有的话,你以前在那里?

When you say the error goes away, do you mean if you delete those last two lines with the if-statement? That would make sense for the reasons stated above.

当你说错误消失时,你的意思是你用if语句删除最后两行吗?由于上述原因,这是有道理的。

#1


0  

You are getting that error because right now you have two if-statements at the bottom of your current program, without a "body" for the what should happen if the conditions of those statements are met.

您正在收到该错误,因为您现在在当前程序的底部有两个if语句,而没有“body”表示如果满足这些语句的条件会发生什么。

Python expects something after the if-statements, hence it encounters the EOF (end-of-file) when it parses your code.

Python在if语句之后需要一些东西,因此它在解析代码时会遇到EOF(文件结尾)。

What, if anything, did you have there before?

你有什么,如果有的话,你以前在那里?

When you say the error goes away, do you mean if you delete those last two lines with the if-statement? That would make sense for the reasons stated above.

当你说错误消失时,你的意思是你用if语句删除最后两行吗?由于上述原因,这是有道理的。