如何使用python打印名称

时间:2019-06-07 04:22:37

标签: python input

我需要通过输入用户名称输入以下代码来打印我的姓名。我需要使用for和if语句。

这是单词的A-Z列表。我知道如何执行输入代码,但不确定如何使用'for'和'if'语句实际循环输入代码。我曾尝试在Google搜索中寻求帮助,但没有任何帮助。

# print A to Z in python for Q7
print("..######..\n..#....#..\n..######..\n..#....#..\n..#....#..\n\n")

print("..######..\n..#....#..\n..#####...\n..#....#..\n..######..\n\n")
print("..######..\n..#.......\n..#.......\n..#.......\n..######..\n\n")

print("..#####...\n..#....#..\n..#....#..\n..#....#..\n..#####...\n\n")
print("..######..\n..#.......\n..#####...\n..#.......\n..######..\n\n")

print("..######..\n..#.......\n..#####...\n..#.......\n..#.......\n\n")

print("..######..\n..#.......\n..#####...\n..#....#..\n..#####...\n\n")

print("..#....#..\n..#....#..\n..######..\n..#....#..\n..#....#..\n\n")

print("..######..\n....##....\n....##....\n....##....\n..######..\n\n")

print("..######..\n....##....\n....##....\n..#.##....\n..####....\n\n")

print("..#...#...\n..#..#....\n..##......\n..#..#....\n..#...#...\n\n")

print("..#.......\n..#.......\n..#.......\n..#.......\n..######..\n\n")

print("..#....#..\n..##..##..\n..#.##.#..\n..#....#..\n..#....#..\n\n")

print("..#....#..\n..##...#..\n..#.#..#..\n..#..#.#..\n..#...##..\n\n")

print("..######..\n..#....#..\n..#....#..\n..#....#..\n..######..\n\n")

print("..######..\n..#....#..\n..######..\n..#.......\n..#.......\n\n")

print("..######..\n..#....#..\n..#.#..#..\n..#..#.#..\n..######..\n\n")

print("..######..\n..#....#..\n..#.##...\n..#...#...\n..#....#..\n\n")

print("..######..\n..#.......\n..######..\n.......#..\n..######..\n\n")

print("..######..\n....##....\n....##....\n....##....\n....##....\n\n")

print("..#....#..\n..#....#..\n..#....#..\n..#....#..\n..######..\n\n")

print("..#....#..\n..#....#..\n..#....#..\n...#..#...\n....##....\n\n")

print("..#....#..\n..#....#..\n..#.##.#..\n..##..##..\n..#....#..\n\n")

print("..#....#..\n...#..#...\n....##....\n...#..#...\n..#....#..\n\n")

print("..#....#..\n...#..#...\n....##....\n....##....\n....##....\n\n")

print("..######..\n......#...\n.....#....\n....#.....\n..######..\n\n")

print("..........\n..........\n..........\n..........\n\n")

print("----..----\n\n")

这是我到目前为止(真的不多):

name=input("Enter a name: ")

例如,如果您的名字是西摩(seymour),则看起来像这样(代码是垂直的,我知道它确实在此网站上水平印刷):

seymour
..######..
..#.......
..######..
.......#..
..######..


..######..
..#.......
..#####...
..#.......
..######..


..#....#..
...#..#...
....##....
....##....
....##....


..#....#..
..##..##..
..#.##.#..
..#....#..
..#....#..


..######..
..#....#..
..#....#..
..#....#..
..######..


..#....#..
..#....#..
..#....#..
..#....#..
..######..


..######..
..#....#..
..#.##...
..#...#...
..#....#..

1 个答案:

答案 0 :(得分:1)

而不是打印它们,而是创建一个dict ...,只是将输入大写并查找

d = {
  # A B C ...
  "G": "..######..\n..#.......\n..#..###..\n..#....#..\n..######..\n\n",
  "H": "..#....#..\n..#....#..\n..######..\n..#....#..\n..#....#..\n\n",
  "I": "..######..\n....##....\n....##....\n....##....\n..######..\n\n",
  "J": "..######..\n....##....\n....##....\n..#.##....\n..####....\n\n",
  "K": "..#...#...\n..#..#....\n..##......\n..#..#....\n..#...#...\n\n"
  # L M N
  # convert the rest of the print statements to dict entries
# print("..#.......\n..#.......\n..#.......\n..#.......\n..######..\n\n")
# print("..#....#..\n..##..##..\n..#.##.#..\n..#....#..\n..#....#..\n\n")

}
def print_word(word):
  for letter in word.upper():
     print(d[letter])

print_word("jIg")