Вот мой код до сих пор:Python печатает все, я только хочу, чтобы напечатать последний номер
import sys
import time
import random
from sys import *
from random import *
from time import sleep
def intro():
global lives
lives = 2
intro1() def intro1():
global lives
text1 = 'please enter (Yes or No)'
for x in text1:
print (x, end='')
sys.stdout.flush()
sleep(0.007)
print()
answer = input()
if 'yes' in answer:
lives = lives + 1
text1 = 'Thank you'
text2 = '+ 1 life'
text3 = lives
text4 = ' lives now.'
for x in text1:
print (x, end='')
sys.stdout.flush()
sleep(0.007)
print()
for x in text2:
print (x, end='')
sys.stdout.flush()
sleep(0.007)
print()
for x in range(text3):
print (x, end='')
sys.stdout.flush()
sleep(0.007)
for x in text4:
print (x, end='')
sys.stdout.flush()
sleep(0.007)
print()
intro1()
if 'no' in answer:
lives = lives - 1
if lives <= 0:
text1 = 'Out of lives. Game Over.'
for x in text1:
print (x, end='')
sys.stdout.flush()
sleep(0.007)
end()
elif lives >= 0:
text1 = 'That\'s rude'
text2 = '- 1 life!'
text3 = lives
text4 = ' lives left'
for x in text1:
print (x, end='')
sys.stdout.flush()
sleep(0.007)
print()
for x in text2:
print (x, end='')
sys.stdout.flush()
sleep(0.007)
print()
for x in range(text3):
print (x, end='')
sys.stdout.flush()
sleep(0.007)
for x in text4:
print (x, end='')
sys.stdout.flush()
sleep(0.007)
print()
intro1()
else:
intro1() def end():
text1 = 'done.'
for x in text1:
print (x, end='')
sys.stdout.flush()
sleep(0.007) intro()
Я знаю, это выглядит очень долго, и сбивает с толку. Программа отлично работает, я ее протестировал. Моя единственная проблема в том, что он печатает все числа.
Ex:
жизни + 1 Спасибо жизнь в настоящее время.
или
Thats грубо - 1 живой 01 жизней осталось.
Я только хочу, чтобы он напечатал последний номер, но я хочу, чтобы он печатался с анимацией, которую у меня есть. Помощь будет принята с благодарностью.
Случайный совет: ваш код анимации один и тот же каждый раз, вы можете использовать его в функции. Затем, если вы поместите строки «text» в список, вы можете перебрать его. Ваш код будет намного короче. – kwinkunks