小编Dav*_* K.的帖子

在Python中为字符串创建打字机效果动画

就像在电影和游戏中一样,一个地方的位置出现在屏幕上,好像它是在现场打字一样.我想做一个关于在python中逃离迷宫的游戏.在游戏开始时,它给出了游戏的背景信息:

line_1 = "You have woken up in a mysterious maze"
line_2 = "The building has 5 levels"
line_3 = "Scans show that the floors increase in size as you go down"
Run Code Online (Sandbox Code Playgroud)

在变量下,我试着为每一行做一个for循环,类似于:

from time import sleep

for x in line_1:
    print (x)
    sleep(0.1)
Run Code Online (Sandbox Code Playgroud)

唯一的问题是它每行打印一个字母.它的时机还可以,但我怎么能让它在一条线上?

python python-3.x

6
推荐指数
2
解决办法
8299
查看次数

如何按值从Python列表中删除项目?

如果我想通过其值而不是索引删除项目,我该怎么办?

animals = ['tiger', 'snake', 'penguin','giraffe']
Run Code Online (Sandbox Code Playgroud)

说我想删除'penguin'而不打字del animals[2]我怎么去呢?

我试过打字,del animals['penguin']但它不起作用......

python list

-1
推荐指数
1
解决办法
109
查看次数

如何在Python中生成一副牌

如何在Python中以列表格式最有效地生成52张卡片,以便列表如下所示:

['1 of Spades', '1 of Hearts', '1 of Clubs', '1 of Diamonds', '2 of Spades', '2 of Hearts' 等等

python

-2
推荐指数
1
解决办法
1648
查看次数

标签 统计

python ×3

list ×1

python-3.x ×1