-1
#Declare main module
def main():

    #declare variables
    age = 0
    weight = 0
    month = ""

    #introduction
    def introduction():
        print("Welcome to Guess the secrects! ")
        print("""I want you to guess the age, wieght, and birth month to
            uncover my secrects!""" )

    #ask user for input
    def get_age():
        age = input("Enter age. ")
        return age

    def get_weight():
        weight = input("Enter weight. ")
        return weight

    def get_month():
        month = input("Enter a birth month. ")
        return month

    def correct_answers():
        age = get_age
        weight = get_weight
        month = get_month

    # We will now determine if the user guess the correct answers
    #using if statements.
    def check_answers(age, weight, month):
        if age <= 25:
            print("Congratulations, the age is 25 or less. ")
        if weight >= 128:
            print("Congratulations, the weight is 128 or more. ")
        if month == "April":
            print("Congratulations, the birth month is April. ")
        else:
            print("Try again! ")

main()

Hello, my problem is that my main function will not run and nothing shows up in the Shell. Any suggestions or guidance will be greatly appreciated.

whackamadoodle3000
  • 6,684
  • 4
  • 27
  • 44
Eddie
  • 7
  • 4
    You have lots of functions but you do not call any of them. – Stephen Rauch Jun 02 '18 at 18:06
  • 1
    Are you declaring functions inside your main function? Your indenting could use fixing in the post to make it clear. Regardless, you need to call the functions like Stephen said. – Jeff Jun 02 '18 at 18:10
  • Where do i call them? – Eddie Jun 02 '18 at 18:19
  • That depends on what you want your code to do. – melpomene Jun 02 '18 at 18:20
  • I want the code to ask the user to guess age numbers, weight, and month and let them know if they got the right answer by congratulating them. – Eddie Jun 02 '18 at 18:24
  • https://docs.python.org/3/library/stdtypes.html?highlight=function#functions – Stephen Rauch Jun 02 '18 at 18:27
  • @Eddie Then why define functions at all? – melpomene Jun 02 '18 at 18:35
  • I want to get better with functions. – Eddie Jun 02 '18 at 18:37
  • Just like your script calls `main()`, so does `main()` need to call the other functions you define. – tripleee Jun 02 '18 at 18:39
  • Thanks for all the help. I called the functions and not it saying NameError: name 'age' is not defined. I tried editing the code but that isnt working either. And i guess stackoverflow is telling me that the question i posted wasn't liked or received well by the community and i could be blocked entirely. It's my first day on this site. – Eddie Jun 02 '18 at 21:52

1 Answers1

1

Your intending of other functions inside your main() function shows that your trying to define a function within a function.

Suggestion: Try converting and your main function into a class and then declare the functions as methods within your main class for example as follows :

class main():

    #introduction
    def __init__ (self):

        #declare variables
        self.age = 0
        self.weight = 0
        self.month = ""
        print("Welcome to Guess the secrects! ")
        print("""I want you to guess the age, wieght, and birth month to
            uncover my secrects!""" )

    #ask user for input
    def get_age(self):
        self.age = input("Enter age. ")
        return self.age

    def get_weight(self):
        self.weight = input("Enter weight. ")
        return self.weight

    def get_month(self):
        self.month = input("Enter a birth month. ")
        return self.month



a = main()
a.get_age()
a.get_weight()
a.get_month()
ssamuel
  • 287
  • 2
  • 7