# create a triangle pattern using * character
# take input from user for max lines to print
# number of * per line should be equal to the line number.
# By default in python 3 input is in string type, we need a integer
r = int(input("Enter max range:"))
for i in range (r+1):
print ( '* ' * i )
that's it.
save the file e.g. startriangle.py
output:
dev@example.net:/home/dev$python3 startriangle.py
Enter max range: 5
*
* *
* * *
* * * *
* * * * *
dev@example.net:/home/dev$
# take input from user for max lines to print
# number of * per line should be equal to the line number.
# By default in python 3 input is in string type, we need a integer
r = int(input("Enter max range:"))
for i in range (r+1):
print ( '* ' * i )
that's it.
save the file e.g. startriangle.py
output:
dev@example.net:/home/dev$python3 startriangle.py
Enter max range: 5
*
* *
* * *
* * * *
* * * * *
dev@example.net:/home/dev$
No comments:
Post a Comment