Hi am a newbie in Python. I have this code for a game where a client types in e.g. as illustrated several cities and the code works out a combination to open a vault. It works well without a while loop but i want a loop where:
1. The first part, the client types in the cities it iterates from any part e.g. the first 5 items , mid 10 items or last n items to get a combination.
2. The next part it gets a combination match using the code matchgame and in the next part iterates again leaving out the last city up to a max of five in a [:-1,-2,-3,-4 and -5] style. It can also change to remove an item from the middle of the list e.g. [1:2:] etc. This is the one to open the vault.
Here is the code:

import matchgame
import FindGame
import teams game
bet = input('please type bet word')

listbet  = [ 'london', 'sydney', 'bombay', 'capetown', lagos', moscow', 'manchester', 'chicago', 'tokyo', 'nairobi', 'singapore']

while True:# need to iterate over RANDOMLY SUGGESTED PLACE IN THE LIST e.g. the first 5 items , middle 10 items or last n items in a loop
    if game == listbet[0]:
        if game == listbet[0] + listbet[1]: 
            if game == listbet[0] + listbet[1] + listbet[2]:
                if game == listbet[0] + listbet[1] + listbet[2] + listbet[3]:
                    if game == listbet[0] + listbet[1] + listbet[2] + listbet[3]: + listbet[4]:
                       while True:# Gets the combination of items from listbet e.g. two ietms, compares with matchgame but iterates it leaving the last item  up to the last 4 items

                           game = ' '.join(listbet)[:-1]# I need code for another loop here for the [:-1],[:-2],[:-3],[:-4],[:-5]
                           game2 = game.split()[:-1]
                           game3 = ' '.join(game2)
                           game4 = Findgame1(game3,teamsgame)
                           matchgame1 = matchgame(game3)
                           matchgame2 = matchgame(game4)
                           match = matchgame.matcgame(matchgame2)
                           if match complete == .001: 
                               print('Got it!)  # a key holder is placed here to open the vault .To be coded late


I need help at the while loop.Regards

I'm sorry, but I would re-write that code if I were you. When you find yourself making several nested if/else statements you should take a step back and re-consider if you're doing this the right way. It's not good programming practices what you're trying to do.

This article has been dead for over six months. Start a new discussion instead.