简体   繁体   中英

why does it not allow me to print "player 1 is x"

I am not able to print('player 1 is x'). what am I doing wrong.

def marker():
    mark = ''
    while mark != 'x' and mark != "o":
        mark = input('select x or o:')
    if mark == 'x':
        print("player 1 is x")

This works on my end. Are you running this with a Python 3 interpreter?

If you are running it with Python 2.7, input() you will need to put quotes around your string input, due to eval() being called on the input, behind the scenes. Otherwise, it will interpret your input as a name. See here for more.

With Python 2.7:

select x or o:"x"
player 1 is x

With Python 3:

select x or o:x
player 1 is x

Just to cover all bases, you are calling this marker function later, correct?

def marker():
    mark = ''
    while mark != 'x' and mark != "o":
        mark = input('select x or o:')
    if mark == 'x':
        print("player 1 is x")

marker() # <---

Is it throwing you any error?, I ran on my local machine with Python 3.7 interpreter and it works fine after calling the method marker().

I am not able to print('player 1 is x'). what am I doing wrong.

def marker():
    mark = ''
    while mark != 'x' and mark != "o":
        mark = input('select x or o:')
    if mark == 'x':
        print("player 1 is x")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM