Python 练习实例73

[复制链接]
1106|0
 楼主| cooldog123pp 发表于 2023-5-27 11:48 | 显示全部楼层 |阅读模式
题目:反向输出一个链表。
程序分析:无。
  1. #!/usr/bin/python
  2. # -*- coding: UTF-8 -*-

  3. if __name__ == '__main__':
  4.     ptr = []
  5.     for i in range(5):
  6.         num = int(raw_input('please input a number:\n'))
  7.         ptr.append(num)
  8.     print ptr
  9.     ptr.reverse()
  10.     print ptr
以上实例输出结果为:
  1. please input a number:
  2. 6
  3. please input a number:
  4. 5
  5. please input a number:
  6. 3
  7. please input a number:
  8. 4
  9. please input a number:
  10. 8
  11. [6, 5, 3, 4, 8]
  12. [8, 4, 3, 5, 6]







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

本版积分规则

2345

主题

7773

帖子

31

粉丝
快速回复 在线客服 返回列表 返回顶部