鱼C论坛

 找回密码
 立即注册
查看: 2201|回复: 6

[已解决]求助如何在Python中实现功能

[复制链接]
发表于 2023-1-20 17:51:43 From FishC Mobile | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
问题是这样的:
    如有这样一行代码print(“你好!世界”)
  想要达到输出时独个字输出,并在输出内容最后位添加闪烁的“_“符号
最佳答案
2023-1-20 17:59:31
  1. from time import sleep
  2. def print_ch(n):
  3.     for i in range(3):
  4.         sleep(0.1)
  5.         print('_', end = '', flush = True)
  6.         sleep(0.1)
  7.         print('\b', end = '', flush = True)
  8.         #print(' ', end = '', flush = True)
  9.     print(n, end = '', flush = True)
  10. def MyPrint(n):
  11.     for i in n:
  12.         print_ch(i)
  13.     print()
  14. MyPrint('你好!世界')
  15. from os import system
  16. system('pause')
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2023-1-20 17:59:31 | 显示全部楼层    本楼为最佳答案   
  1. from time import sleep
  2. def print_ch(n):
  3.     for i in range(3):
  4.         sleep(0.1)
  5.         print('_', end = '', flush = True)
  6.         sleep(0.1)
  7.         print('\b', end = '', flush = True)
  8.         #print(' ', end = '', flush = True)
  9.     print(n, end = '', flush = True)
  10. def MyPrint(n):
  11.     for i in n:
  12.         print_ch(i)
  13.     print()
  14. MyPrint('你好!世界')
  15. from os import system
  16. system('pause')
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

发表于 2023-1-20 19:34:56 | 显示全部楼层
本帖最后由 chinajz 于 2023-1-20 19:39 编辑

楼上正解。
楼主不会是想这个效果吧:
  1. #coding=gbk
  2. from time import sleep
  3. for i in '"你好!世界"':
  4.     sleep(0.5)
  5.     print(i, end = '', flush = True)
  6. print("\n")
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

发表于 2023-1-20 20:18:19 | 显示全部楼层
         楼主如果希望看到 Linux 文字终端上的各种彩色文字效果,需要下载安装 ANSICON。
  1. https://github.com/adoxa/ansicon/releases/
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-1-20 20:21:20 | 显示全部楼层
chinajz 发表于 2023-1-20 19:34
楼上正解。
楼主不会是想这个效果吧:


是这个效果。不过没闪烁的_。。
总之谢谢你~
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-1-20 20:22:08 | 显示全部楼层

大佬膜拜,谢谢!
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-1-20 21:09:04 | 显示全部楼层
1838569480 发表于 2023-1-20 20:22
大佬膜拜,谢谢!

对上面那位大佬的代码进行了小小的修改

  1. from time import sleep
  2. def print_ch(n):
  3.     for i in range(3):
  4.         print('_', end = '', flush = True)
  5.         sleep(0.1)
  6.         print('\b ', end = '', flush = True)
  7.         sleep(0.1)
  8.         print('\b', end = '', flush = True)
  9.     print(n, end = '', flush = True)
  10. def MyPrint(n):
  11.     for i in n:
  12.         print_ch(i)
  13.     print()
  14. MyPrint('你好!世界')
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-27 04:28

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表