The Student Room Group

AS Computer Science - AQA Warships

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?
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:":wink:
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 :h:
Reply 2
Any Chance you could copy and paste and unmended version of all the code?
Reply 3
It looks like you typed in a file name when it wanted you menu option, and therefore your block of code was never executed...

Quick Reply

Latest

Trending

Trending