python 猜单词小游戏
        【摘要】     
 文章目录
 0.效果1.代码
 
 
0.效果 
 
 
1.代码 
# 猜单词游戏
import random #添加
WORDS = ("python","juice","easy","difficult","answer","continue","phone","hello","pose","game")
print("欢迎参加猜单词游戏\n把字母组合成一...
    
    
    
    0.效果

1.代码
# 猜单词游戏
import random #添加
WORDS = ("python","juice","easy","difficult","answer","continue","phone","hello","pose","game")
print("欢迎参加猜单词游戏\n把字母组合成一个正确的单词")
iscontinue = "Y"
while iscontinue=="Y" or iscontinue=="Y": #循环 #从序列中随机挑出一个单词 word = random.choice(WORDS) #一个判断玩家是否猜对的变量 correct = word #创建乱序后的单词 jumble = "" print(word) while word: #word不是空字符串 #根据word长度,产生word的随机位置 position = random.randrange(len(word)) #将position位置字母组合到乱序的单词 jumble+=word[position] #通过切片,将position位置字母从原单词中删除 word = word[:position]+word[(position+1):] print("乱序后的单词:",jumble) guess = input("\n请你猜:") while guess != correct and guess !="": print("对不起。不正确") guess = input("继续猜") if guess == correct: print("真棒,你猜对了") iscontinue = input("\n是否继续(Y/N):") #是否继续游戏
  
 - 1
 - 2
 - 3
 - 4
 - 5
 - 6
 - 7
 - 8
 - 9
 - 10
 - 11
 - 12
 - 13
 - 14
 - 15
 - 16
 - 17
 - 18
 - 19
 - 20
 - 21
 - 22
 - 23
 - 24
 - 25
 - 26
 - 27
 - 28
 
刚学习要注意 python没有分号,它的缩进就是判断逻辑持续位置,要注意缩进,否则会出错。
文章来源: blog.csdn.net,作者:花狗Fdog,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/Fdog_/article/details/106207297
        【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
            cloudbbs@huaweicloud.com
        
        
        
        
        
        
        - 点赞
 - 收藏
 - 关注作者
 
            
           
评论(0)