我试图使这个ASCII列表在每一行中间隔10和1行。我不能不把桌子弄乱就把它们分开。我要它不要吐出一排字。
桌子应该是这样的。
! " # $ % & ' ( ) *
+ , - . / 0 1 2 3 4
5 6 7 8 9 : ; < = >
? @ A B C D E F G H
I J K L M N O P Q R
S T U V W X Y Z [ \
] ^ _ ` a b c d e f
g h i j k l m n o p
q r s t u v w x y z
{ | } ~ 这是我的代码:
for v in range(33,127):
if v <= 42:
print(chr(v), end = ' ')
elif v >= 43 and v <= 52:
print(chr(v), end = ' ')
elif v >= 53 and v <= 62:
print(chr(v), end = ' ')
elif v >= 63 and v <= 72:
print(chr(v), end = ' ')
elif v >= 73 and v <= 82:
print(chr(v), end = ' ')
elif v >= 83 and v <= 92:
print(chr(v), end = ' ')
elif v >= 93 and v <= 102:
print(chr(v), end = ' ')
elif v >= 103 and v <= 112:
print(chr(v), end = ' ')
elif v >= 113 and v <= 122:
print(chr(v), end = ' ')
elif v >= 123 and v <= 127:
print(chr(v), end = ' ')
else:
break发布于 2014-10-12 22:41:00
以下是代码:
start = 33
end = 127
for v in range(start, end):
if (start - v) % 10 == 0: # check if (start - v) is a multiple of 10
print("")
print(chr(v), end=' ')发布于 2014-10-12 22:37:01
Python是一种非常灵活的语言。这会让你得到你想要的大部分:
print "\n".join(" ".join(map(chr, range(x, x+10))) for x in range(33, 128, 10))这超出了最后一行所需的最大值127。把它作为一项练习留给你。
发布于 2020-02-13 22:24:13
我想了解.format 字符串格式 in python3,所以我想出了一个简单的方法来完成这个任务。
print(5*' '+(16*'{:#4x}').format(*range(16)),
*['{:#4x}|'.format(i*16) + (16*'{:4c}').format(*range(16*i,16*(i+1)))
for i in range(2,8)], sep="\n")输出:
0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xa 0xb 0xc 0xd 0xe 0xf
0x20| ! " # $ % & ' ( ) * + , - . /
0x30| 0 1 2 3 4 5 6 7 8 9 : ; < = > ?
0x40| @ A B C D E F G H I J K L M N O
0x50| P Q R S T U V W X Y Z [ \ ] ^ _
0x60| ` a b c d e f g h i j k l m n o
0x70| p q r s t u v w x y z { | } ~ 不完全是什么命令,但在我看来,更多的美学。
说明:'{:#4x}'.format(val)在字段4字符宽(4)中输出val (假定的int)格式为十六进制(x),其前面的0x (#)。16*'{:4c}'创建16个字段,4个字符宽,它们将获得的任何int格式化为char,这是由可迭代解包装表达式*range(...)提供的。
https://stackoverflow.com/questions/26330645
复制相似问题