• Welcome to SpeedSolving.com — the world’s largest puzzle community!

    You’re currently browsing as a guest, which means you have limited access to discussions, resources, member profiles, and community features.

    Join 50,000+ cubers and puzzle enthusiasts from around the world to ask questions, share solves, improve faster, and be part of the community.

    Registration is free, fast, and easy — create your account today.

    Already a member? Log in here to hide this message and start participating.

what is wrong with my python code

Xflighenjoyer

Regular
Joined
Dec 31, 2025
Messages
44
Location
America
it should be printing something or at least showing something but it isn't:

def intput():
x=0
try:
x=int(input("please enter a number: "))
return x
except:
intput()
import copy
#will run brainfuck code given in the variable brainf_ckcode
brainf_ckcode="++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++..."
okaycharslist=['+','-','>','<',',','.','[',']']
okaycharslistshort=['+','-','>','<',',','.']
def format(brainfuckcode):
brainfucklist=[]
incomment=False

for char in range(len(brainfuckcode)):
if brainfuckcode[char]=='(':
incomment=True
if brainfuckcode[char]==')':
incomment=False
if not incomment:
if brainf_ckcode[char] in okaycharslist:
brainfucklist.append(str(brainf_ckcode[char]))
else:
print("char not in list, \n dont worry though \n so long as the brainfsck \n are syntatctically fine \n itll work")
return brainfucklist
class brainf_cktape:
def __init__(self):
self.theactualtape=[]
self.pointer=0
for _ in range(1024):
self.theactualtape.append(0)
def add1(self):
self.theactualtape[self.pointer]+=1
def substract1(self):
if self.theactualtape[self.pointer]<1:
self.theactualtape[self.pointer]=255
else:
self.theactualtape[self.pointer]-=1
def movepointerforward(self):
self.pointer=(self.pointer+1)%len(self.theactualtape)
def movepointerbackward(self):
self.pointer=(self.pointer-1)%len(self.theactualtape)
def setvalue(self):
self.theactualtape[self.pointer]=intput()%256
def __str__(self):
return([self.pointer,])
brainfcktape=brainf_cktape()
def runchar(char,tape1):
tape2=copy.deepcopy(tape1)
if char in okaycharslistshort:
if char=='+':
tape2.add1()
if char=='-':
tape2.substract1()
if char==">":
tape2.movepointerforward()
if char=="<":
tape2.movepointerbackward()
if char==",":
tape2.setvalue()
if char==".":
print(tape2.theactualtape[tape2.pointer])
return tape2
return tape2
else:
print("error: giving runchar invalid characters")
return tape2
print(format(brainf_ckcode))
def runbrainfck(brainfck):
brainfck2=format(brainfck)
char=0
bracketdisplacement=0
while char<len(brainfck2):
if char>=len(brainfck2):
break
print(str(char)+brainf_ckcode[char])
if brainfck2[char] in okaycharslistshort:
runchar(brainfck2[char],brainfcktape)
else:
if brainfck2[char]==']':
if not brainfcktape.theactualtape[brainfcktape.pointer]==0:
bracketdisplacement=1
while bracketdisplacement!=0:
char-=1
print(char)
if brainfck2[char]=='[':
bracketdisplacement-=1
print(brainfck[char])
print(bracketdisplacement)
elif brainfck2[char]==']':
bracketdisplacement+=1

char+=1
print("end")
print(brainfcktape.theactualtape)
runbrainfck(brainf_ckcode)
 
Back
Top