import random
cityList = []
usedcityList = []
intermediatedict = []
userCityInput = ''
counter = 0
with open('citylist.txt','r') as fileCL:
textCityList = fileCL.readlines()
for textCL in textCityList:
textCL = textCL.strip()
cityList.append(textCL)
def checkforamatch(arguserCityInput):
for xcityList in cityList:
if xcityList == arguserCityInput:
global counter
counter += 1
for xusedcityList in usedcityList:
if xusedcityList == xcityList:
counter = 0
return 1
counter = 0
usedcityList.append(arguserCityInput)
return 0
if counter > 0:
return -1
def lastleter(arguserCityInput):
return arguserCityInput[-1:]
def findword(letter):
for xcityList in cityList:
if letter == xcityList[0]:
intermediatedict.append(xcityList)
randomWord = random.randrange(0,(len(intermediatedict)-1))
for xusedcityList in usedcityList:
if xusedcityList == cityList[randomWord]:
findword(letter)
else:
intermediatedict.clear()
usedcityList.append(cityList[randomWord])
return cityList[randomWord]
while True:
print('Введите город:')
userCityInput = input()
result = checkforamatch(userCityInput)
if result == 1:
print('\nГород уже был использован в Игре.')
if result == 0:
resultlast = lastleter(userCityInput)
resultlast = findword(resultlast)
print(resultlast)
if result == -1:
print('\nТакого города не существет.')
Решил реализовать игру города, вопрос такой, почему в функции findword не добавляется слово в промежуточный список intermediatedict?