#This simple Function for string does not work

20 messages · Page 1 of 1 (latest)

ivory dragon
#
Crtmark = ''
def MarkChoice_f():
    
    MarkChoice = int(input('1. For X \n2. For O \n'))
        # 1 = X, 2= O, symbols
        
    if MarkChoice == 1 or MarkChoice == 'O': 
        Crtmark = 'X'
    elif MarkChoice == 2 or MarkChoice == 'X':
        Crtmark = 'O'

    return Crtmark
        

Its result is a blank space

stark badger
#

Can you show how you're using the return from this function?

#

I feel like this function should explode given you're mirroring a variable name from the global scope.

ivory dragon
ivory dragon
stark badger
#

You're not using the function on that line. The variable inside the function has no effect on the variable outside the function. You need to capture the functions return into a variable.

Crtmark = MarkChoice_f()
#

Your function is very likely broken though.

#

It doesn't account for invalid inputs

ivory dragon
#

I'll try to finish it tomorrow

stark badger
#

Why do you need a do/while?

ivory dragon
ivory dragon
stark badger
#

Can you show the code that's giving that error? (I'm at work so may not respond right away)

ivory dragon
#
 box[UserInput] = MarkChoice_f() ```
stark badger
#

Ok yeah that's what I thought would happen. You're not accounting for when the input isn't valid. What did you enter when you got the input prompt?

ivory dragon
ivory dragon
#

2 first time and 4 second time, after 4 it crashed