0

Help needed from my pyramid code

a 1 2. 3 4. 9. 2 7. 6. 0 3 ______________________ import random line=5 def pyramid(line): for each in range(1,line+1): yield ' '*int((each/(each+1)*line) for i in range(1,each+1): yield str(random.randint(1,9)) yield str('\n') pyramid=pyramid(line) print(' '.join(pyramid))

10th Jan 2018, 1:07 AM
Yololab
Yololab - avatar
3 Réponses
+ 2
Parenthesis missmatch at line 5... it should be: yield ''*int(each/(each+1)*line) ... or: yield ''*int((each/(each+1))*line) However, that will only fix the Python syntax error, and you will get output, but not the one you expect ;P Unfortunally, I doesn't understood what's the logic of your pyramid should be ^^
10th Jan 2018, 7:12 AM
visph
visph - avatar
+ 1
Replace the space used for the join() method to better see what doesn't work as expected: print('.'.join(pyramid)) You'll see that you add a character at start of each line appart the first one, so you can fix it by: print(' '+' '.join(pyramid))
10th Jan 2018, 1:39 PM
visph
visph - avatar
0
I am sorry for my mistake 🙈 ___________________ import random line=5 def pyramid(line): for each in range(1,line+1): yield ' '*(line-each) for i in range(1,each+1): yield str(random.randint(1,9)) yield str('\n') pyramid=pyramid(line) print(' '.join(pyramid)) ______________ do you know why the first line of output is wrong ?
10th Jan 2018, 10:19 AM
Yololab
Yololab - avatar