替换Python中的输出

时间:2019-05-13 20:38:34

标签: python printing

我有一个小的命令行Hold'em手生成器:

http://localhost:55722/reset-password/my_parameter_here

这样的输出:

hole_cards = deck.draw(2)
h1, h2 = hole_cards
print(f'Your Hole Cards: {h1} | {h2}\n')

flop_cards = deck.draw(3)
f1, f2, f3 = flop_cards
print(f'Flop: {f1} | {f2} | {f3}\n')

turn_card = deck.draw(1) 
t = turn_card[0]
print(f'Turn: {f1} | {f2} | {f3} | {t}\n')

river_card = deck.draw(1)
r = river_card[0]
print(f'River: {f1} | {f2} | {f3} | {t} | {r}\n')

有什么办法,而不是在翻牌后打印转牌和河牌,而是先用翻牌再加上河牌来代替翻牌一词?我知道我可以在同一行上打印新卡,但是我不知道如何替换已经打印的单词“ flop”或“ turn”

2 个答案:

答案 0 :(得分:0)

尝试这样的事情:

import time

for i in range(5):
    print('{} of 5'.format(i), end='\r')
    time.sleep(1)

答案 1 :(得分:0)

在您的打印语句中添加end =“ \ r”,您的输出将替换为新内容:

hole_cards = deck.draw(2)
h1, h2 = hole_cards
print(f'Your Hole Cards: {h1} | {h2}', end="\r")

flop_cards = deck.draw(3)
f1, f2, f3 = flop_cards
print(f'Flop: {f1} | {f2} | {f3}', end="\r")

turn_card = deck.draw(1) 
t = turn_card[0]
print(f'Turn: {f1} | {f2} | {f3} | {t}', end="\r")

river_card = deck.draw(1)
r = river_card[0]
print(f'River: {f1} | {f2} | {f3} | {t} | {r}', end="\r")