Click here to Skip to main content
15,888,060 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is my first month on programming languange, the lecturer told me to make a triangle pattern with Python. On this case, the lecturer want to make pattern with simbols only (ex:!, @, #, $, %, ^, *) and forbid any alphabets/number. The pattern is worked, but i have trouble by making it only working with simbols character to build the triangle.

What I have tried:

a = int(input("Input amount of rows   : "))
k = str(input("Insert the pattern character: "))
s = a - 1 #for space
ks=["!","@","#","$","%","^","&","*","-","+","="]
if a<100:
    if k == ks:
        for i in range(0, a):
            for j in range(0, s):
                print(' ', end='')
            s -= 1
            for j in range(0, i + 1):
                print('',k, end='')
 
            print(' ')
    else:
        print("Character inconvenient")
else:
     print("The number of rows inconvenient")
Posted
Updated 13-Oct-22 18:21pm
v2

1 solution

What I think your teacher means is that you should restrict the user input to a number (the rows count) and a symbol - and that the symbol should be checked: it should be in the list you gave.

Once you have the character, you start printing the triangle.

That means reading the symbol inside a loop: if it's in the list, exit the loop - if it isn't, tell him what it can be, and go around again. == between the string the user input and a list of strings doesn't do that.

Python has an operator which checks if an item is in a list: Python Membership Operators - in and not in[^] which would help you.
 
Share this answer
 
Comments
CPallini 14-Oct-22 7:28am    
5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900