eMRe
eMRe

Reputation: 3247

How to pass value to a function

I am new to python and doing this homework. I need to create a small program with menu. I was very good 'til now. I am a little bit lost. How can I pass a value to the function? Can you please check if there are any other faults in my code.

import turtle as t


def how_many():
    while True:  
        print "  How many of then do you want to draw?"
        print "  (Range is from 1 to 5)"
        shape_no = raw_input('  Enter your choice: ')
        try: 
            shape_no = int(shape_no)
            if (1 <= shape_no <= 5):
                print "Your number is ok"
                break
            else:
                print
                print "from 1 to 5 only"

        except:
            print "Only numbers allowed - Please try again"
    return True


#=========#=========#=========#=========#=========#=========#=========#


def draw_square():
    t.penup() 
    t.setpos(-200,0) 
    t.pendown()

    Number_of = 5
    for a in range(Number_of): 
        for a in range(4): 
            t.forward(60) 
            t.left(90)
        t.penup() 
        t.forward(80)
        t.pendown()

#=========#=========#=========#=========#=========#=========#=========#
def main():
    while True:
        print
        print "  Draw a Shape"
        print "  ============"
        print
        print "  1 - Draw a square"
        print
        print "  X - Exit"
        print

        choice = raw_input('  Enter your choice: ')

        if (choice == 'x') or (choice == 'X'):
            break
        elif choice == '1':
            how_many()
            draw_square()
        else:
            print 'Try again'



#=========#=========#=========#=========#=========#=========#=========#
if __name__ == "__main__":
    main()

#=========#=========#=========#=========#=========#=========#=========#

Upvotes: 0

Views: 480

Answers (1)

user97370
user97370

Reputation:

For how to define and call functions, see the Python tutorial.

For code review, try https://codereview.stackexchange.com/

Upvotes: 4

Related Questions