python实现输入任意一个大写字母生成金字塔的示例

作者:代序春秋 时间:2022-02-04 10:27:19 

输入任意一个大写字母,生成金字塔图形


def GoldTa(input):
 L = [chr(i) for i in range(65, 91)] # 大写字母A--Z
 idA = 65 # 从A开始
 # ord()函数将字母转换为Unicode数值
 idInput = ord(input)
 num = idInput - idA + 1 # 输入的字符个数
 tempResult = ""
 for C in range(0, num):
   for C1 in range(0, C): # 左 [ABC]
     tempResult = tempResult + L[C1]
   tempResult = tempResult + L[C] # 中 [D]
   for C2 in range(C - 1, -1, -1): # 右 [CBA]
     tempResult = tempResult + L[C2]
   for C3 in range(num - 1 - C): # 每行空格
     tempResult = " " + tempResult
   print(tempResult) # 输出
   tempResult = "" # 清空临时结果

while True:
 char = input("请输入一个大写字母:")
 if char.isupper():
   GoldTa(char)
   continue
 else:
   print("输入错误,请重新输入")

结果如下:

 python实现输入任意一个大写字母生成金字塔的示例

来源:https://blog.csdn.net/geek64581/article/details/102743524

标签:python,金字塔
0
投稿

猜你喜欢

  • 使用pyinstaller打包PyQt4程序遇到的问题及解决方法

    2023-11-04 11:21:26
  • pandas创建新Dataframe并添加多行的实例

    2021-06-21 07:11:48
  • 番茄的js表单验证类

    2008-01-07 13:53:00
  • 使用anaconda的pip安装第三方python包的操作步骤

    2022-11-20 04:05:22
  • 学生如何免费使用Pycharm专业版学生认证教程

    2021-11-20 16:25:13
  • 基于Linux系统中python matplotlib画图的中文显示问题的解决方法

    2022-05-22 01:34:28
  • 使用ASP订制自己的XML文件读写方法

    2008-10-24 09:35:00
  • pyinstaller封装exe的操作

    2021-02-12 03:21:16
  • Python 实现定积分与二重定积分的操作

    2023-08-05 18:22:27
  • 终于搞懂了Python中super(XXXX, self).__init__()的作用了

    2022-01-04 00:35:44
  • SQL Server查询速度慢原因及优化方法

    2008-12-03 15:19:00
  • python 插入日期数据到Oracle实例

    2022-09-29 23:51:59
  • 正则 global 属性介绍

    2008-03-18 20:50:00
  • 9行Python3代码实现批量提取PDF文件的指定内容

    2023-02-12 03:22:41
  • python os.path.isfile()因参数问题判断错误的解决

    2021-06-24 08:17:47
  • python 字典(dict)遍历的四种方法性能测试报告

    2023-08-21 21:27:08
  • Python爬虫之正则表达式基本用法实例分析

    2022-12-20 17:02:16
  • asp加载access数据库并生成XML文件范例

    2008-07-22 12:41:00
  • ASP.Net MVC 布局页、模板页使用方法详细介绍

    2023-06-28 19:24:31
  • 对Python w和w+权限的区别详解

    2022-11-30 09:40:15
  • asp之家 网络编程 m.aspxhome.com