I am new on Python and I am following a book that purposes the following excercise:
Write a program to generate the following pattern in Python:
*
**
***
****
The suggested code is:
n = input('Enter the number of rows: ')
m = int(n)
*k = 1
for i in range(m):
for j in range(i, i + 2):
print('*', end = " ")
print()
and enter n=5
.This lead me to ask to questions. The first one is the *k=1
, I am asumming the '' is a typo on the book since my program does not run with it. However i am not seeing that k
is being used within the loop. My second question is that I do not understand why my outcome is different than the one I get (once removed the ''). This is what I get when n=5
:
**
**
**
**
**
Aucun commentaire:
Enregistrer un commentaire