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

2024-09-26 22:12:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我是计算机科学专业的一年级学生,对自己的工作一无所知,我真的需要一些帮助。我正在为一个任务编写一个程序,它将运行一个模拟,用户从三只股票中选出一只,程序将计算10年的收益/损失。

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

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

我已经在网站上搜索了以前的解决方案,但是正如我所说的,我对编程还很陌生,而且我对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:

我很感激你的帮助。


Tags: 程序ifdefstock收益returnsmenurisk
1条回答
网友
1楼 · 发布于 2024-09-26 22:12:49

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

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

什么,如果有的话,你以前有过吗?

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

相关问题 更多 >

    热门问题