使用用户输入进行Python打印

时间:2019-06-18 00:23:50

标签: python

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

这是字母A-Z的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")

例如,输入名称seymour将产生以下输出:

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


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


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


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


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


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


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

我尝试通过代码使用'while'和'if'语句,但是它一直在说语法错误。下面是到目前为止的代码。

    name= input('Enter name: ')
    i=0 
    while i<0 len(name):s
    if i== 'A' or 'a' then print("..######..\n..#....#..\n..######..\n..#....#..\n..#....#..\n\n")
    if S[i]= 'B' or 'b' then print("..######..\n..#....#..\n..#####...\n..#....#..\n..######..\n\n")
    if S[i]= 'C' or 'c' then print("..######..\n..#.......\n..#.......\n..#.......\n..######..\n\n")
    if S[i]= 'D' or 'd' then print("..#####...\n..#....#..\n..#....#..\n..#....#..\n..#####...\n\n")
    if S[i]= 'E' or 'e' then print("..######..\n..#.......\n..#####...\n..#.......\n..######..\n\n")
    if S[i]= 'F' or 'f' then print("..######..\n..#.......\n..#####...\n..#.......\n..#.......\n\n")
    if S[i]= 'G' or 'g' then print("..######..\n..#.......\n..#####...\n..#....#..\n..#####...\n\n")
    if S[i]= 'H' or 'h' then print("..#....#..\n..#....#..\n..######..\n..#....#..\n..#....#..\n\n")
    if S[i]= 'I' or 'i' then print("..######..\n....##....\n....##....\n....##....\n..######..\n\n")
    if S[i]= 'J' or 'j' then print("..######..\n....##....\n....##....\n..#.##....\n..####....\n\n")
    if S[i]= 'K' or 'k' then print("..#...#...\n..#..#....\n..##......\n..#..#....\n..#...#...\n\n")
    if S[i]= 'L' or 'l' then print("..#.......\n..#.......\n..#.......\n..#.......\n..######..\n\n")
    if S[i]= 'M' or 'm' then print("..#....#..\n..##..##..\n..#.##.#..\n..#....#..\n..#....#..\n\n")
    if S[i]= 'N' or 'n' then print("..#....#..\n..##...#..\n..#.#..#..\n..#..#.#..\n..#...##..\n\n")
    if S[i]= 'O' or 'o' then print("..######..\n..#....#..\n..#....#..\n..#....#..\n..######..\n\n")
    if S[i]= 'P' or 'p' then print("..######..\n..#....#..\n..######..\n..#.......\n..#.......\n\n")
    if S[i]= 'Q' or 'q' then print("..######..\n..#....#..\n..#.#..#..\n..#..#.#..\n..######..\n\n")
    if S[i]= 'R' or 'r' then print("..######..\n..#....#..\n..#.##...\n..#...#...\n..#....#..\n\n")
    if S[i]= 'S' or 's' then print("..######..\n..#.......\n..######..\n.......#..\n..######..\n\n")
    if S[i]= 'T' or 't' then print("..######..\n....##....\n....##....\n....##....\n....##....\n\n")
    if S[i]= 'U' or 'u' then print("..#....#..\n..#....#..\n..#....#..\n..#....#..\n..######..\n\n")
    if S[i]= 'V' or 'v' then print("..#....#..\n..#....#..\n..#....#..\n...#..#...\n....##....\n\n")
    if S[i]= 'W' or 'w' then print("..#....#..\n..#....#..\n..#.##.#..\n..##..##..\n..#....#..\n\n")
    if S[i]= 'X' or 'x' then print("..#....#..\n...#..#...\n....##....\n...#..#...\n..#....#..\n\n")
    if S[i]= 'Y' or 'y' then print("..#....#..\n...#..#...\n....##....\n....##....\n....##....\n\n")
    if S[i]= 'Z' or 'z' then print("..######..\n......#...\n.....#....\n....#.....\n..######..\n\n")
  File "program.py", line 3
    while i<0 len(name):s
                ^
SyntaxError: invalid syntax

这就是结果。我试图修复它,但随后每行都出现相同的问题。

1 个答案:

答案 0 :(得分:1)

如果条件为S [i] =='G'或 S [i] == 'g'

新代码:

name = input('Enter name: ')

for char in name:
    if char == 'A' or char == 'a': print("..######..\n..#....#..\n..######..\n..#....#..\n..#....#..\n\n")
    elif char == 'B' or char == 'b': print("..######..\n..#....#..\n..#####...\n..#....#..\n..######..\n\n")
    elif char == 'C' or char == 'c': print("..######..\n..#.......\n..#.......\n..#.......\n..######..\n\n")
    elif char == 'D' or char == 'd': print("..#####...\n..#....#..\n..#....#..\n..#....#..\n..#####...\n\n")
    elif char == 'E' or char == 'e': print("..######..\n..#.......\n..#####...\n..#.......\n..######..\n\n")
    elif char == 'F' or char == 'f': print("..######..\n..#.......\n..#####...\n..#.......\n..#.......\n\n")
    elif char == 'G' or char == 'g': print("..######..\n..#.......\n..#####...\n..#....#..\n..#####...\n\n")
    elif char == 'H' or char == 'h': print("..#....#..\n..#....#..\n..######..\n..#....#..\n..#....#..\n\n")
    elif char == 'I' or char == 'i': print("..######..\n....##....\n....##....\n....##....\n..######..\n\n")
    elif char == 'J' or char == 'j': print("..######..\n....##....\n....##....\n..#.##....\n..####....\n\n")
    elif char == 'K' or char == 'k': print("..#...#...\n..#..#....\n..##......\n..#..#....\n..#...#...\n\n")
    elif char == 'L' or char == 'l': print("..#.......\n..#.......\n..#.......\n..#.......\n..######..\n\n")
    elif char == 'M' or char == 'm': print("..#....#..\n..##..##..\n..#.##.#..\n..#....#..\n..#....#..\n\n")
    elif char == 'N' or char == 'n': print("..#....#..\n..##...#..\n..#.#..#..\n..#..#.#..\n..#...##..\n\n")
    elif char == 'O' or char == 'o': print("..######..\n..#....#..\n..#....#..\n..#....#..\n..######..\n\n")
    elif char == 'P' or char == 'p': print("..######..\n..#....#..\n..######..\n..#.......\n..#.......\n\n")
    elif char == 'Q' or char == 'q': print("..######..\n..#....#..\n..#.#..#..\n..#..#.#..\n..######..\n\n")
    elif char == 'R' or char == 'r': print("..######..\n..#....#..\n..#.##...\n..#...#...\n..#....#..\n\n")
    elif char == 'S' or char == 's': print("..######..\n..#.......\n..######..\n.......#..\n..######..\n\n")
    elif char == 'T' or char == 't': print("..######..\n....##....\n....##....\n....##....\n....##....\n\n")
    elif char == 'U' or char == 'u': print("..#....#..\n..#....#..\n..#....#..\n..#....#..\n..######..\n\n")
    elif char == 'V' or char == 'v': print("..#....#..\n..#....#..\n..#....#..\n...#..#...\n....##....\n\n")
    elif char == 'W' or char == 'w': print("..#....#..\n..#....#..\n..#.##.#..\n..##..##..\n..#....#..\n\n")
    elif char == 'X' or char == 'x': print("..#....#..\n...#..#...\n....##....\n...#..#...\n..#....#..\n\n")
    elif char == 'Y' or char == 'y': print("..#....#..\n...#..#...\n....##....\n....##....\n....##....\n\n")
    elif char == 'Z' or char == 'z': print("..######..\n......#...\n.....#....\n....#.....\n..######..\n\n")