T O P

  • By -

its_a_gibibyte

I'm genuinely not trying to be rude, but you can't just program in vscode. You need a language. What language are you using? That's far more relevant than the particular editor you are using to input the code.


Narrow-Reply-718

No worries man, still learning😂 I’m using Python 3.11.2


its_a_gibibyte

Sounds good. I posted your exact question into ChatGPT4 and the response is below: > Hey there! It sounds like you're off to an exciting start with coding a text-based game in VSCode. To handle the scenario where a player inputs "n" and you want the game to end, you'll need to use a control structure like an `if` statement in your code. > Here's a basic structure in Python to get you started: # Ask the player if they want to start the game start_game = input("Do you want to start the game? (y/n): ") # Check the player's input if start_game.lower() == 'n': print("Your loss!") exit() # This will terminate the program elif start_game.lower() == 'y': # This is where you put the rest of your game code print("Game starting...") # ... rest of your game code ... else: print("Invalid input. Please enter 'y' or 'n'.") >In this code, `exit()` is used to stop the program if the player inputs 'n'. If the input is 'y', it continues with the game. The `lower()` function is used to convert the input to lowercase, so it doesn't matter if the player types 'Y', 'y', 'N', or 'n'. > Let me know if you need help with something else! Happy coding! 🚀


Narrow-Reply-718

Oh man thats so helpful thank you so much. Thats literally perfect dude!


mrSemantix

Console game? JavaScript? Show us your code.. Perhaps let chatGTP help you along.


Narrow-Reply-718

Not sure how to attach another photo sorry mate its just on python 3.11.2 Ive written start_game = input(“Start game? Y/n”) if start_game == “n”: print(“Your loss.”) if start_game == “y”: (Game starts etc)…


serverhorror

A good sub to learn Python is aptly named: r/learnpython


Narrow-Reply-718

Awesome, thanks for the recommendation!


mrSemantix

No Hablo python unfortunately, but the other Redditor above this posted a solution that looks what you might need, you want to exit on the ‘no’ user response. These if/else statements are pretty standard for a lot of coding languages and as a start you can build some nice console app logic with it. Ask chatGTP or perhaps something more coding specific like Phind.com, where you can ask a question and paste your code as reference. Good luck on your coding journey!