0

I need to write a code for printing my name as below by taking the user input for a name. I need to use for and if statements.

Here is an A-Z list of the letters A-Z. I know how to do the input code but I am unsure of how to actually loop it using 'for' and 'if' statements. I have tried to google search for help but nothing has helped. I have already asked this question but have changed my initial work. The code keeps saying syntax error.

    # 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")

For example, entering the name seymour would produce this output:

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


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


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


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


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


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


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

I have tried to use 'while' and 'if' statements using the code but it keeps saying syntax error. Below is my code so far.

    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

This is what comes up. I tried to fix it, but then every other line comes up with the same thing.

5
  • Have you removed the 's' after the colon? Commented Jun 18, 2019 at 0:34
  • @saltchicken yes sorry, i must of accidentally pressed on it. However, this is not the cause of my problem :) Commented Jun 18, 2019 at 0:36
  • if/then is not valid python. Also you are using or incorrectly. Try if S[i] == 'B': print('## whatever'). Convert the whole string to upper case before the loop, so you havent got to try to match both cases. Commented Jun 18, 2019 at 0:43
  • The eror message shows you (approximately) where the error is. Namely, you are missing a colon after your while statement. The command should be while i < len(name): (note the colon). You also need to remove the 0 and the s from the line. Then you need to indent all the if s that follow the while statement. You also do not handle the ors correctly in your if statements. (This is a logic error, not a syntax error.) The previous comment points out that then does not belong in Python. You have a lot of learning to do about Python! Commented Jun 18, 2019 at 0:43
  • here is how it could be done by switching out the chain of ifs for a dict, which maps the chars to what is to be printed. Commented Jun 18, 2019 at 0:49

1 Answer 1

1

Your if condition should be if S[i] == 'G' or S[i] == 'g'

New code:

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")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.