Array in Python array

Asked 2 years ago, Updated 2 years ago, 61 views

# -*- coding: utf-8 -*-

#country = [san_fransico,cicago,montrial,new_york,washington,atlelanta,miami,mexico_city,los_angeles,bogota,saint_paaulu,Bueno,rima,santiago]
country=["san","ci","mon","new","at","wa","los","mex","mi","bo","san","bue","ri","sant"]
san=["ci"]
ci=["mon","at","los","mex","san"]
mon=["ci","new"]
new=["wa","mon"]
at=["ci","wa","mi"]
wa=["new","at","mi"]
los=["mex","ci"]
mex=["ci","los","mi"]
mi=["at","wa","mex","bo"]
bo=["san","bue","ri"]
san=["bo","bue"]
bue=["san","bo"]
ri=["bo","sant"]
sant=["ri"]

player_1 = [wa]
player_2 = [wa]

check=raw_input ("set position? (start game?) [y/n]")

if check is "y":
    while 1:
        place=raw_input ("Where do you want to move?")

        for s in player_1[0]:
            if place in s:
                player_1[0]=place
                print("Place player_1 ""+place+")" has been moved to "+place+""
                print("The current location of player_1 is ""+place+"" (Location of player_1 is "+place+")")

            elif place not in s:
                print ("Can't move")
                break

elif check is "n":
    print ("end")

else:
    print("Invalid command_error")

I want to change the information of index 0 of player_1 to the value of place, but it is possible to go to "new", but it does not change to "at",mi".

Example of running a program) If you are currently in wa, replace the information in player_1 with another array of the names of elements in the wa array.

python array

2022-09-22 17:57

1 Answers

There is not enough explanation of what you are trying to do, so it is hard to understand what the code is trying to do. Write down specifically what you're trying to do.

One thing is for sure, I think we need to study more repetitive sentences and control sentences.

for s in player_1[0]:

Line above

for s in player_1:

Try modifying it like this.

And if there is an infinite loop in the code and the check is in progress with y,

print ("end")

does not do so.


2022-09-22 17:57

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.