+ 1
Can anyone tell me wats wrong with this code?
9 Answers
+ 3
Currently function pyramid prints a line but returns nothing i.e. None . Replace print with str since you want to return string not list. Also add 'return' before str, because you want the pyramid function to return the string value.
short version: replace 'print' with 'return str'
still you will not get a number pyramid, but I'll leave it up to you to figure that out :) spaces are reverse proportional to the n value.
* str(arg) function converts arg to string
+ 3
pyramid() doesn't have a return statement, so its returned value is 'None'
+ 2
#I think you want like this.
#pyramid of numbers
x = int(input("input: "))
def pyramid(n):
print(list(range(n+1))[::-1] + list(range(1, n+1)))
for n in range(x+1):
print(str(n)*(n))
pyramid(n)
+ 2
#Or like this?
#pyramid of numbers
x = int(input("input: "))
print()
def pyramid(n):
print(list(range(n+1))[::-1] + list(range(1, n+1)))
return n
for n in range(x+1):
print((" "*(n-1),pyramid(n)))
+ 2
I think I figured it out
#pyramid of numbers
x = int(input("input: "))
def pyramid(n):
return str(list(range(n+1))[::-1] + list(range(1, n+1)))
for n in range(x+1):
print(" "*(x-n) + pyramid(n))
+ 2
š just add one empty print() under input() or \n to input
+ 1
@Ferhat sevim
not exactly but thanks anyway
+ 1
š thanks
0
a clean code by villux https://code.sololearn.com/cz8a9o6i07l1/?ref=app