实现屏幕广告语的滚动
代码如下:
import time
adv=input("请输入一段广告语:")
while 1:
fx=input("请输入滚动的方向(L/R)").upper()
if fx in ['L','R']:
break
print("您输入的有误,请重新输入!")
while 1:
sd=input("请输入滚动的速度(请输入一个整数):")
if sd.isnumeric():
break
print("您输入的有误,请重新输入!")
while 1:
if fx=="R":
adv=adv[-1]+adv[:-1]
else:
adv=adv[1:]+adv[0]
print('\r'+adv,end='',flush=True)
time.sleep(int(sd))
结果如下:
请输入一段广告语:welcome to 西安!
请输入滚动的方向(L/R)l
请输入滚动的速度(请输入一个整数):3
lcome to 西安!we