Hey there! Sign in to join this conversationNew here? Join for free
    • Thread Starter
    Offline

    2
    ReputationRep:
    I need help with a question, the program I'm using is Python

    Question: This question refers to the main program. Option 3 currently just displays a message. Amend it so that it prompts the user for a filename and then loads this file and plays the game.

    Code:
    if MenuOption ==3:
    FileName=input("Please enter name of file:")
    LoadGame(FileName, Board)
    PlayGame(Board,Ships)


    However, when I do amend the code and input 'Training.txt' as the file name it says this:
    Traceback (most recent call last):
    File "F:\Computer Science\Topics 1-4\Exam\Paper 1 - Copy.py", line 189, in <module>
    MenuOption = GetMainMenuChoice()
    File "F:\Computer Science\Topics 1-4\Exam\Paper 1 - Copy.py", line 161, in GetMainMenuChoice
    Choice = int(input())
    ValueError: invalid literal for int() with base 10: 'Training.txt'

    How do I fix this?
    • TSR Community Team
    Offline

    20
    ReputationRep:
    TSR Community Team
    (Original post by iram_b)
    I need help with a question, the program I'm using is Python

    Question: This question refers to the main program. Option 3 currently just displays a message. Amend it so that it prompts the user for a filename and then loads this file and plays the game.

    Code:
    if MenuOption ==3:
    FileName=input("Please enter name of file:"
    LoadGame(FileName, Board)
    PlayGame(Board,Ships)


    However, when I do amend the code and input 'Training.txt' as the file name it says this:
    Traceback (most recent call last):
    File "F:\Computer Science\Topics 1-4\Exam\Paper 1 - Copy.py", line 189, in <module>
    MenuOption = GetMainMenuChoice()
    File "F:\Computer Science\Topics 1-4\Exam\Paper 1 - Copy.py", line 161, in GetMainMenuChoice
    Choice = int(input())
    ValueError: invalid literal for int() with base 10: 'Training.txt'

    How do I fix this?
    Hi! I moved this the the Computer Science forum - you're more likely to get a good discussion here
    Offline

    1
    ReputationRep:
    Any Chance you could copy and paste and unmended version of all the code?
    Offline

    0
    ReputationRep:
    It looks like you typed in a file name when it wanted you menu option, and therefore your block of code was never executed...
 
 
 
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • Poll
    Would you like to hibernate through the winter months?
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

    Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

    Quick reply
    Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.