例题:python: 怎样写一个函数把名字大写并变成下面这样?
字典+列表:将每个字母以列表形式存在字典里,分六次打印输出:
dic = { } dic['C']=[ ' CCCC ', ' C C', 'C ', 'C ', ' C C', ' CCCC ' ] dic['A']=[ ' A ', ' A A ', ' A A ', ' AAAAAAA ', ' A A ', 'A A' ] dic['T']=[ 'TTTTTTT', ' T ', ' T ', ' T ', ' T ', ' T ' ] dic['R']=[ 'RRRRR ', 'R R ', 'R R ', 'RRRRR ', 'R R ', 'R R' ] dic['E']=[ 'EEEEEE', 'E ', 'EEEE ', 'E ', 'E ', 'EEEEEE' ] for count in range(6): print dic['C'][count], print dic['A'][count], print dic['T'][count], print dic['E'][count], print dic['R'][count]
错误尝试:如果将CARTER五个字符看作四个键值对,用三引号存放在字典里,则只能竖着输出一列。代码如下:
dic = { } dic['C']=''' CCCC C C C C C C CCCC''' dic['A']=''' A A A A A AAAAAAA A A A A''' dic['T']=''' TTTTTTT T T T T T''' dic['R']=''' RRRRR R R R R RRRRR R R R R''' dic['E']=''' EEEEEE E EEEE E E EEEEEE''' print dic['C'],dic['A'],dic['R'],dic['T'],dic['E'],dic['R']这段代码打印出来结果是
版权声明:欢迎转载,转载请注明出处http://blog.csdn.net/ztf312/
python: 怎样写一个函数把名字大写并变成下面这样——字典与三引号
原文地址:http://blog.csdn.net/ztf312/article/details/47321735