
Python Editor — Persistent Snapshot + Load from File
Autosave snapshot (code + output) to localStorage. Load/Save snapshots to file. Floating output available.
Output & Logs
Output will appear here after running your code.
Loaded packages: none
Tip: Editor autosaves a snapshot ({code, output}) to localStorage. Use Save/Load buttons to exchange snapshots as files.
3 Comments

Pascal's Triangle in Python
def pascal(y,x):
if x==1:
return 1
if y==x:
return 1
return pascal(y-1,x-1) + pascal(y-1,x)
n=5
for y in range(1,n+1):
for space in range(1, n-y+1):
print(" ",end="")
for x in range(1,y+1):
value=pascal(y,x)
print(value,end=" ")
print()
def pascal(y,x):
if x==1:
return 1
if y==x:
return 1
return pascal(y-1,x-1) + pascal(y-1,x)
n=5
for y in range(1,n+1):
for space in range(1, n-y+1):
print(" ",end="")
for x in range(1,y+1):
value=pascal(y,x)
print(value,end=" ")
print()

Palindrome checker
def isPalindrome(n):
copy=n
reverse=0
while n>0:
rem=n%10
n=n//10
reverse=reverse*10 + rem
if copy==reverse:
return True
return False
x=int(input())
result=isPalindrome(x)
if result:
print(f"{x} is a palindrome")
else:
print(f"{x} is not a palindrome")
def isPalindrome(n):
copy=n
reverse=0
while n>0:
rem=n%10
n=n//10
reverse=reverse*10 + rem
if copy==reverse:
return True
return False
x=int(input())
result=isPalindrome(x)
if result:
print(f"{x} is a palindrome")
else:
print(f"{x} is not a palindrome")

Palindrome numbers
def isPalindrome(n):
copy=n
reverse=0
while n>0:
rem=n%10
n=n//10
reverse=reverse*10 + rem
if copy==reverse:
return True
return False
x=int(input())
if isPalindrome(x):
print("+ve=",x,"-ve=",x)
else:
copy=x
while True:
if isPalindrome(x):
print(x)
break
x+=1
p=x
x=copy
while True:
if isPalindrome(x):
print(x)
break
x-=1
n=x
print("+ve=",p,"-ve=",n)
def isPalindrome(n):
copy=n
reverse=0
while n>0:
rem=n%10
n=n//10
reverse=reverse*10 + rem
if copy==reverse:
return True
return False
x=int(input())
if isPalindrome(x):
print("+ve=",x,"-ve=",x)
else:
copy=x
while True:
if isPalindrome(x):
print(x)
break
x+=1
p=x
x=copy
while True:
if isPalindrome(x):
print(x)
break
x-=1
n=x
print("+ve=",p,"-ve=",n)
3 Comments
def pascal(y,x):
if x==1:
return 1
if y==x:
return 1
return pascal(y-1,x-1) + pascal(y-1,x)
n=5
for y in range(1,n+1):
for space in range(1, n-y+1):
print(" ",end="")
for x in range(1,y+1):
value=pascal(y,x)
print(value,end=" ")
print()
def isPalindrome(n):
copy=n
reverse=0
while n>0:
rem=n%10
n=n//10
reverse=reverse*10 + rem
if copy==reverse:
return True
return False
x=int(input())
result=isPalindrome(x)
if result:
print(f"{x} is a palindrome")
else:
print(f"{x} is not a palindrome")
def isPalindrome(n):
copy=n
reverse=0
while n>0:
rem=n%10
n=n//10
reverse=reverse*10 + rem
if copy==reverse:
return True
return False
x=int(input())
if isPalindrome(x):
print("+ve=",x,"-ve=",x)
else:
copy=x
while True:
if isPalindrome(x):
print(x)
break
x+=1
p=x
x=copy
while True:
if isPalindrome(x):
print(x)
break
x-=1
n=x
print("+ve=",p,"-ve=",n)