!python3!

so i was trying to get a for loop to work to get a program to choose which part of the code it had to run, this is what i have:

while True:
    whichcode = 1
#set the variable for the first time.

for whichcode == 1:
    print code nr 1
    print where to go?
    print 1 or 2 or 3?
    x = input()
    if x == 1:
        whichcode = 1
    if x == 2:
        whichcode = 2
    if x == 3:              #let the user choose
        whichcode = 3       #which piece of code it should go to.

for whichcode == 2:
    print code nr 2
    print where to go?
    print 1 or 2 or 3?
    x = input()
    if x == 1:
        whichcode = 1
    if x == 2:
        whichcode = 2       #let user choose again.
    if x == 3:
        whichcode = 3

for whichcode == 3:
    print code nr 3
    print where to go?
    print 1 or 2 or 3?
    x = input()
    if x == 1:
        whichcode = 1   
    if x == 2:
        whichcode = 2       #and again.
    if x == 3:
        whichcode = 3

when trying to compile i got a syntax error for the first for loop, at the place of the "==" it gives the error, not at any other, just at this one.
it this just wrong usage of the for expression or am i doing something else wrong? if else, what am id doing wrong?

Recommended Answers

All 2 Replies

I read some info on the for statement and decided to make use of if for what im trying to do. the new code i have placed in a new thread to avoid confusion

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.