Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can anyone help me find out whats wrong with my code? something isnt right but python says its fine

The code is functioning. Python says the code is executing, but it wont print anything. Ive looked around and i cant find anything that answers my question. why wont the code print the print statements? Ive only been learning python on the ocr gcse specification for about 2yrs now so im not the most advanced. Ive had to do extra reserch on things ive already learned to get where i am now. This project is due on the morning of 27.3.23 and its currently the evening of 24.3.23. i only have 3 days to complete it and i dont know why the code wont work. any help will be highly appreciated.

the code i currently have is Here:

#imports needed for game

import sys
import os


#sets a class for the player
class player:
    def __init__(self):
       self.name=' '
       self.hp = 0
       self.sa = []
   
#title screen
def title_selections():
    option = input("> ")
    if option.lower() == ("play"):
         start_game() #place holder until written
    
    elif option.lower == ("help"):
            help_screen()
        
    elif option.lower() == ("quit"):
        sys.exit()
    
    while option.lower() not in ['play','help','quit']:
        def title_selections():
            option = input("> ")
        if option.lower() == ("play"):
            start_game() #place holder until written
    
        elif option.lower == ("help"):
            help_screen()
        
        elif option.lower() == ("quit"):
             sys.exit()
#outputted title screen

def title_selections():
    os.system('clear')

    print('######################')
    print('#Welcome adventurer!#')
    print('######################')
    print('       -Play          ')
    print('       -Help          ')
    print('       -Quit         ')

#help screen:
def help_screen():
    print('######################')
    print('#Welcome adventurer!#')
    print('######################')
    print('-The DM (Dungeon Master) will ask you questions.')
    print('-And as the player, it is your choice to decide what your character will do.')
    print('-In certain situations, you will be required to answer these questions with              great thought!')
    print('-So remember to think carefully when answering these questions.')
    print('-Or any questions for that matter!')
    print('-Proceed with caution, and remember to have fun!')

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I noticed a few issues here.

  1. title_selections is defined twice – I solved this by moving the code from the 2nd definition into the top of the first
  2. Functions are never called – I called title_selections() at the bottom of the code
  3. On the two lines where you check if the input is "help", you are missing the parentheses in option.lower() – I added the parentheses to both option.lower() calls
  4. You define a function inside of an if statement inside of another function – I removed the function definition

Here’s the code all fixed up:

# imports needed for game

import sys
import os


# sets a class for the player
class player:
    def __init__(self):
        self.name = ' '
        self.hp = 0
        self.sa = []


# title screen
def title_selections():
    os.system('clear')

    print('######################')
    print('#Welcome adventurer!#')
    print('######################')
    print('       -Play          ')
    print('       -Help          ')
    print('       -Quit         ')

    option = input("> ")
    if option.lower() == ("play"):
        # start_game()  # place holder until written
        x = 0
    elif option.lower() == ("help"):
        help_screen()

    elif option.lower() == ("quit"):
        sys.exit()

    while option.lower() not in ['play', 'help', 'quit']:
        option = input("> ")

        if option.lower() == ("play"):
            # start_game()  # place holder until written
            x = 0
        elif option.lower() == ("help"):
            help_screen()

        elif option.lower() == ("quit"):
            sys.exit()


# help screen:
def help_screen():
    print('######################')
    print('#Welcome adventurer!#')
    print('######################')
    print('-The DM (Dungeon Master) will ask you questions.')
    print('-And as the player, it is your choice to decide what your character will do.')
    print('-In certain situations, you will be required to answer these questions with              great thought!')
    print('-So remember to think carefully when answering these questions.')
    print('-Or any questions for that matter!')
    print('-Proceed with caution, and remember to have fun!')


title_selections()


Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading