Text Generator
Text Generator > Use Cases >Python bug fixer

Python bug fixer

There's a number of ways of structuring the prompt for checking for bugs. Here we add a comment suggesting that source code is buggy, and then ask codex to generate a fixed code.

Example input

  • ##### Fix bugs in the below function ### Buggy Python import Random a = random.randint(1,12) b = random.randint(1,12) for i in range(10): question = "What is "+a+" x "+b+"? " answer = input(question) if answer = a*b print (Well done!) else: print("No.") ### Fixed Python

Example real generated results

  • star

    version from math import * a=random.randint(0,6) b=random.randint(0,3) print 'Number of squares that can be filled with '+str((a+b-1))+' is:' ans1=int(ceil(((a+1)*b)))//2 if ans1!=0: for x in xrange(ans1-1,len(x)): ans2=ceil(((x-1+abs(a-b))/2)) if ((x+ans2-1)!=0 and abs(x-b)==1-ans2-1 or ((x+1-ans2-2)!= 0)and abs(x-a-1)!=-1 ) : break if ans1%2: ans1+=2 print 'Number:' + str(ans1) def rand_answer(): return int(input()) # Question 2 """Question 3 """ n

  • star

    3 from __future__ import division,print_function def _randint(): return int((float(random().getrandbits(63)) / 8192)) def randrange(start=1,end=200005): # max 20005 -> 20 digits while end >= start: temp = end-start+1 end = temp//2 start += 1 for p in range(temp%3,0,-1): if ((end % 2)!=0) and (((p * 3) < (2*temp))): break; else: start += 1; end-=2; break return start + p; RANDINT_MAX=10**16 ; RNDMAX=10**5; RNGMAX=205; def Randonumber(num_of_digits=5): while num_of_digits > 0: digit = str

  • star

    3 def ask_for_number_1_and_2(): """Ask for 2 numbers and check them. Output whether they are equal. Input will be either 0 or 1""" nums = [int(n) for n in input().split()] if abs(nums[0] - nums[1])!= 1: return False elif (not (isinstance(nums, list)) or not len(nums)): return True # If we get an integer instead of two strings... just assume it makes sense. return None if __name__ == '__main__': ans1 = ask_for_number_1_and_2() if ans1: # Yes its one number only. print("Yes.") continue ask_for_number_1_and_2() ask_for_number_1_and_2() ## while True: ## nums = ask_for_number_1_and_2()

  • star

    from math import sqrt a=int(input()) b=int(input()) c=a*b;print(a+b+c%16==4 or b-c%2==0 and c-a-b+a%6==0 or c-b%2==0 and a+ab+1%d2==0or c-eb+1%d2=13or a+cb+2%d2==14or ab+d2+c%=18 or bc=d1+c2==1 or d1=dc+4d%7>0 or d1-ca+9d%3>3 ) '''def test(): n=random.randrange(0,1000) mid=n//2;k=n-mid*2 ans="NO ANSWER"%mid if mid<=k: ans+=str((mid/2)) elif k<mid: ans+=str((k-mid)**2) return ans test() ''' def find_solutions(i

try it yourself: Text Generator Playground - Python bug fixer