社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

如何在python的列表中找到输入的位置[副本]

scarab • 5 年前 • 1786 次点击  

我现在正在构建一个简单的刽子手游戏,我希望能够识别用户在列表中猜测特定字母的位置例如,如果单词列表是[D,R,A,G,O,N]——而用户猜测是A,那么我希望能够得到一个返回值,即4……这是我迄今为止失败的代码

import random

word_list = ['red', 'better', 'white', 'orange', 'time']
hidden_list = []
selected_word = random.choice(word_list)
letters = len(selected_word)
selected_word_list = list(selected_word)
game_playing = True

print('My word has ' + str(letters) + ' letter(s).')

print(selected_word_list)

for i in selected_word_list:
    hidden_list.append('_')

while game_playing:
    print(hidden_list)
    guess = input('What letter do you want to guess?')
    if guess in selected_word_list:
        print('Nice guess!')
    else:
        print('Nope!')
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/49240
 
1786 次点击  
文章 [ 3 ]  |  最新文章 5 年前