Jump to content

Wikipedia:Reference desk/Archives/Computing/2020 February 21

From Wikipedia, the free encyclopedia
Computing desk
< February 20 << Jan | February | Mar >> February 22 >
Welcome to the Wikipedia Computing Reference Desk Archives
The page you are currently viewing is a transcluded archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages.


February 21

[edit]

How to sign up for a Weixin account as a Foreigner?

[edit]

I need to ask technical questions to developpers of Chineese software who don t know me (200000 different users but not well known outside borders).
And of course, the rule is no email, no GitHub, no Stack Exchange, but Weixin QR codes on the project s website which by the way isn t translated.

I read that in order to talk to mainland Chineese users, I need Weixin as WeChat is a version preventing to talk to mainland.

The problem is I don t know any Chineese user, and as I don t live in Asia, I ve no idea on how to get a Chineese mobile phone number (even temporary). 193.55.65.121 (talk) 14:33, 21 February 2020 (UTC)[reply]

You might ask on WP:RDL (more Chinese speakers there) if you don't get a useful response here reasonably soon. Could you use a Hong Kong VPN? I think those are easy to get. 2601:648:8202:96B0:0:0:0:7AC0 (talk) 22:03, 21 February 2020 (UTC)[reply]
Location is based on mobile phone number not ip address. Do you have an idea for a Chineese mobile phone number? 37.171.180.227 (talk) 09:58, 23 February 2020 (UTC)[reply]
No, no, no, no, Weixin is WeChat if you're a foreigner. It's the same program except it's in English. The userbase is identical between the two programs. You guys are making this more complicated than you need to. My copy of WeChat doesn't prevent me from talking with any of my students or friends in the mainland because neither my nor their account has been suspended. Ian.thomson (talk) 22:42, 21 February 2020 (UTC)[reply]
Thank you. Can you help me to enroll then? [[1]] 37.171.180.227 (talk) 09:58, 23 February 2020 (UTC)[reply]
I just went to their website, downloaded the app, and followed the instructions in it. That's it. I registered my account on a US phone and have had to change the number three times since but it still works. Just talked with some friends in Hangzhou earlier today. Ian.thomson (talk) 10:39, 23 February 2020 (UTC)[reply]
But as you can see on this picture from the app https://i.stack.imgur.com/ZEfG3.jpg, I need an other WeChat user to authorize me signing up. But while I want to ask questions to WeChat users. They are strangers who don t know me. So I don t know anyone who can help me.
Are you a mainland national? 193.55.65.121 (talk) 13:05, 24 February 2020 (UTC)[reply]
I think the reason for the above confusion is that WeChat has been getting stricter and stricter. If you've been using WeChat outside of China for a long time, you may have no problem. If not and want to register now, WeChat will often decide your account is suspicious and require the above mentioned process [2] [3] It is true that you can also easily do stuff making it more likely [4] [5] [6]. And to be clear, this is just for ordinary WeChat. If you want WeChat Pay, give up. (Again if you set it up long ago in the past, maybe you'll be fine. Now....) Nil Einne (talk) 07:59, 26 February 2020 (UTC)[reply]
As explained above, I simply never went into China. So, the app is requiring an existing WeChat (can be anyone) user to allow me to sign up even with a Chineese temporary/shared phone number. And yes this is for ordinary WeChat. 37.165.220.176 (talk) 12:06, 26 February 2020 (UTC)[reply]

What is the problem with this code now?

[edit]

Here is the relevant code:


#!/usr/bin/env python3

if __name__ == '__main__':

    def check_board_fullness(board):
        for item in board:
            if board[item] == ' ':
                return False
            return True
    
    #Creates the board
    board = {'top-L': ' ', 'top-M': ' ', 'top-R': ' ',
                'mid-L': ' ', 'mid-M': ' ', 'mid-R': ' ',
                'low-L': ' ', 'low-M': ' ', 'low-R': ' '}
    def print_board(board):
        print(board['top-L'] + '|' + board['top-M'] + '|' + board['top-R'])
        print('-+-+-')
        print(board['mid-L'] + '|' + board['mid-M'] + '|' + board['mid-R'])
        print('-+-+-')
        print(board['low-L'] + '|' + board['low-M'] + '|' + board['low-R'])
        
    #Function to quit
    def end(move):
        if move == 'quit':
            raise SystemExit
        
    #Function to check if any player has won
    def check_winner(board):
        if board['top-L'] == board['top-M'] == board['top-R']:
            if board['top-L'] == 'O':
                return 'O'
            elif board['top-L'] == 'X':
                return 'X'
            else:
                return False
        elif board['top-L'] == board['mid-M'] == board['low-R']:
            if board['top-L'] == 'O':
                return 'O'
            elif board['top-L'] == 'X':
                return 'X'
            else:
                return False
        elif board['top-L'] == board['mid-L'] == board['low-L']:
            if board['top-L'] == 'O':
                return 'O'
            elif board['top-L'] == 'X':
                return 'X'
            else:
                return False
        elif board['top-R'] == board['mid-M'] == board['low-L']:
            if board['top-R'] == 'O':
                return 'O'
            elif board['top-R'] == 'X':
                return 'X'
            else:
                return False
        elif board['top-M'] == board['mid-M'] == board['low-M']:
            if board['top-M'] == 'O':
                return 'O'
            elif board['top-M'] == 'X':
                return 'X'
            else:
                return False
        elif board['top-L'] == board['mid-L'] == board['low-L']:
            if board['top-L'] == 'O':
                return 'O'
            elif board['top-L'] == 'X':
                return 'X'
            else:
                return False
        elif board['mid-L'] == board['mid-M'] == board['mid-R']:
            if board['mid-L'] == 'O':
                return 'O'
            elif board['mid-L'] == 'X':
                return 'X'
            else:
                return False
        elif board['low-L'] == board['low-M'] == board['low-R']:
            if board['low-L'] == 'O':
                return 'O'
            elif board['low-L'] == 'X':
                return 'X'
            else:
                return False
        else:
            return False

    turn = 'O'
    while check_board_fullness(board) == False:
        while check_winner(board) == False:
            print_board(board)
            print("It is now",turn,"'s turn to make a move. What is your move?: ")
            inp = input()
            if inp in board and board[inp] == ' ':
                board[inp] = turn
                if turn == 'O':
                    turn = 'X'
                elif turn == 'X':
                    turn = 'O'
            else:
                print("That's not a valid move!\n")
                inp = input("Please make another move: ")
                if turn == 'X':
                    turn = 'O'
                elif turn == 'O':
                    turn = 'X'
    if check_winner(board) == 'X':
        print("X wins!")
    if check_winner(board) == 'O':
        print("O wins!")
    if check_board_fullness(board) == True and check_winner(board) == False:
        print("It's a tie!")

Basically, I run the program. First, it's O's turn to make a move, so I say top-R. Then I do mid-R for X. Then I do mid-M for O and then low-R for X. Finally, I do low-L for O, but then the program stops or freezes for some reason.

This is what the final part of the computer terminal looks like when this program stops or freezes:

 | |O
-+-+-
 |O|X
-+-+-
 | |X
It is now O 's turn to make a move. What is your move?: 
low-L

Why exactly is this happening and what exactly can I do to fix this? Basically, I'm having O win this game, but the program fails to actually register this victory and this final move for whatever reason.

Anyway, any thoughts on this? Futurist110 (talk) 22:30, 21 February 2020 (UTC)[reply]

You have two nested while loops. Once there is a win, the condition of the inner loop fails, so it becomes equivalent to a null statement. But since the condition of the outer loop is still true, it goes on looping. What you should do is combine the two into a single while loop, joining their conditions with and. I also notice that the program will not print the final board. What you can do is put one call of print_board(board) just before the while loop, and another just after the program has made the (validated) move on the board by executing board[inp] = turn.  --Lambiam 00:03, 22 February 2020 (UTC)[reply]
You will learn faster if you step through your program with a debugger, because then you will see exactly what your code is doing. Using a debugger just to step through code is very simple, though you could speed up the process by learning to set breakpoints. https://docs.python.org/3/library/pdb.html is the documentation for pdb, and https://stackoverflow.com/questions/4929251/how-to-step-through-python-code-to-help-debug-issues also gives useful advice. Best of all, once you've learned how to use one debugger, the concepts will apply to any others, so if you move on to a different programming language you'll find using its debugger easy.-gadfium 01:39, 22 February 2020 (UTC)[reply]
The main alternative to a debugger is putting in print statements to show what it is doing as it runs. Add them strategically to make sure things are as you expect around where the program goes wrong. That usually helps you figure out the problem. Most of your program development time will be spent debugging rather than writing new code, so debugging is an essential skill. Newly written code almost never works, so you have to get used to finding the errors. It might help to sit down with an experienced programmer and have them guide you through debugging this code, and maybe refactoring it to some extent. 2601:648:8202:96B0:C8B1:B369:A439:9657 (talk) 05:19, 22 February 2020 (UTC)[reply]
I too would advise this alternative. Python being as interactive as it is, it is really easy to add some print statements that are tailored to helping you figure out what is how going wrong, and also to comment them out when they seem no longer needed. (Wait with deleting until you are sure everything is fine – you may need them again.) Here is another, more general remark about coding practice. Often there are different program entities that represent or determine the same conceptual entity. If the program modifies one representing entity, then usually the other needs to be adjusted too in order to maintain their proper relationship. A very simple example is a list of numbers (entity 1) together with their total (entity 2). If a number in the list is changed, or one is added to or removed from the list, the total needs to be updated. It is good to be explicitly aware of such relationships that must be kept invariant, so that the code for the necessary updates is properly added. In this case the state of the game has both an internal representation (the variable named board) and an external one (the printout). The invariant to be maintained is that they represent the same state of the game. Each change to the value of variable board (first its initialization; next each move by a player) should be accompanied by an update of the board's printout.  --Lambiam 09:56, 22 February 2020 (UTC)[reply]