-3

When I run the following program in Python, the function takes the variables in, but completely skips over the rest and re-shows the main menu for the program without doing anything. Plus, it skips the qualifying "if" statements and asks for all the variables even if the first or second options are chosen (which don't need the third variable). BTW, It shouldn't be an indent error, I just indented to show it was code inside stackoverflow.

EDIT: NEVERMIND. I got it to work. The variables in the function parenthesis all have to be the same. DUH! smacks forehead

option = 1
while option !=0:
    print "\n\n\n************MENU************"
    print "1. Counting"
    print "2. Fibbonacci Sequence"
    print "0. GET ME OUTTA HERE!"
    print "*" * 28
    option = input("Please make a selection: ") #counting submenu
    if option == 1:

        print "\n\n*******Counting Submenu*******"
        print "1. Count up by one"
        print "2. Count down by one"
        print "3. Count up by different number"
        print "4. Count down by different number"
        print "*" * 28
        countingSubmenu = input("Please make a selection: ")
        x=0
        y=0
        z=0
        q=0
        def counting (x, y, z, countingSubmenu, q):
            x = input("Please choose your starting number: ")
            y = input("Please choose your ending number: ")
            if countingSubmenu == 1:
                for q in range (x, y+1, 1):
                    print q
            elif countingSubmenu == 2:
                for q in range (x, y, -1):
                    print q
            elif countingSubmenu == 3:
                z = input("Please choose an increment: ")
                for q in range (x, y+1, z):
                    print q
            else:
                z = input("Please choose an increment: ")
                for q in range (x, y, -z):
                    print q
            return x, y, z, q
        if countingSubmenu == 1:
            counting(countingSubmenu, x, y, z, q)
        if countingSubmenu == 2:
            counting(countingSubmenu, x, y, z, q)
        if countingSubmenu == 3:
            counting(countingSubmenu, x, y, z, q)
        if countingSubmenu == 4:
            counting(countingSubmenu, x, y, z, q)
Artjom B.
  • 61,146
  • 24
  • 125
  • 222
Brandon Paul
  • 3
  • 1
  • 2
  • 1
    "NEVERMIND. I got it to work. The variables in the function parenthesis all have to be the same. " This is a bad kind of update. Please remove it. Please post an **answer** with the information other people need to figure out what is going on. It's okay to answer your question. It's not okay to apologize. It's better to delete it than to provide such a confusing update. – S.Lott Sep 02 '11 at 01:51

4 Answers4

5

Your function is defined as counting (x, y, z, countingSubmenu, q), but when you're calling it, you're argument list is counting(countingSubmenu, x, y, z, q).

Demian Brecht
  • 21,135
  • 5
  • 42
  • 46
3

It seems to be working in python 2.7 (see Chris Phillips answer)

Anyway few improvements you can do

  • take out function counting out of the loop
  • you need not call counting four times, instead just call counting(countingSubmenu, x, y, z, q)
  • counting function takes parameter in different order and you are passing it in wrong order
  • you need not pass x, y, z as you are asking that from user
Anurag Uniyal
  • 85,954
  • 40
  • 175
  • 219
3

You didn't mention which version of Python you are using, but I suspect it's from the 3.x series. Python 3 changed the behavior of input() to match what was previously raw_input() in the 2.x series.

So, input() now always returns a string. So you either need to call int() or eval() on the result (personally, I suggest int()).

Chris Phillips
  • 11,607
  • 3
  • 34
  • 45
1

Your problem is you are passing the arguments to counting() in the wrong order.

wim
  • 338,267
  • 99
  • 616
  • 750