mardi 3 août 2021

Replacing value in list based on input and dictionary ;-;

i'm only starting to learn python so i only know the basics for now ><

I need to print out a 4x4 table that's labeled ( A B C D ) horizontally and 1234 vertically and ask the user to place a randomly generated number in the table (eg. A1, B2)

num = randomly generated number

table = [ [' ', ' ', ' ', ' '],\
            [' ', ' ', ' ', ' '],\
            [' ', ' ', ' ', ' '],\
            [' ', ' ', ' ', ' ']]
ans = input('where would you like to place it?')

I used a dictionary to assign A1 : table[0][0] and so on Tried to replace the value by doing

if ans in dictionary:
    table.replace(dictionary.get(ans),num)
       

it's not working for me but i only understand how to do it this way :(

Aucun commentaire:

Enregistrer un commentaire