爛尾程序
最近挺想做一個python寫入程序的,但是因為本人技術原因?qū)е聽€尾,現(xiàn)在將源代碼發(fā)布,希望大家能幫助完成
from easygui import *
msgbox('請確保你已經(jīng)在同文件夾內(nèi)創(chuàng)建文本文檔')
a=enterbox('請輸入文件名(加后綴名)')
x=open(a,'a')
a=textbox('請在下面粘貼上次保存的代碼(如果沒有輸入none)')
b='y'
c=[]
d=[]
e=[]
f=['while','for']
g=0
if (a!='none'):
? ? x.write(a)
while b=='y':
? ? a=buttonbox('是否要導入庫','無',('turtle','random','easygui','none'))
? ? b=enterbox('是否要導入多個庫(y/n)')
? ? if (a=='turtle'):
? ? ? ? x.write('from turtle import *')
? ? ? ? c=['forward','backword','right','left','circle','dot','begin_fill','end_fill','color']
? ? elif (a=='random'):
? ? ? ? x.write('from random import *')
? ? ? ? y=open('random.txt','r')
? ? ? ? d=['random','randint']
? ? elif (a=='easygui'):
? ? ? ? x.write('from easygui import *')
? ? ? ? msgbox('在使用這個庫之前,請確保您已安裝這個庫')
? ? ? ? e=['enterbox','msgbox','buttonbox']
? ? elif (a=='none'):
? ? ? ? break
c=c+d+e+f
a=buttonbox('接下來請問你要創(chuàng)建什么','無',('創(chuàng)建變量','創(chuàng)建函數(shù)','創(chuàng)建循環(huán)','調(diào)用函數(shù)'))
if a=='創(chuàng)建變量':
? ? b=enterbox('變量名')
? ? x.write(b+'+')
elif a=='創(chuàng)建函數(shù)':
? ? b=enterbox('函數(shù)名')
? ? x.write('def'+b+':')
? ? b='y'
? ? while b==y:
? ? ? ? g=enterbox('請?zhí)砑雍瘮?shù)')
? ? ? ? x.write(g)
? ? ? ? b=enterbox('是否繼續(xù)創(chuàng)建(y/n)')
elif a=='創(chuàng)建循環(huán)':
? ? a=buttonbox('創(chuàng)建哪種循環(huán)','無',('for','while'))
? ? if (a=='for'):
? ? ? ? b=enterbox('設置循環(huán)次數(shù)')
? ? ? ? x.write('for i in range('+b+'):')
? ? else:
? ? ? ? b=enterbox('請設置循環(huán)條件')
? ? ? ? x.write('while '+b+':')
elif a=='調(diào)用函數(shù)':
? ? a=buttonbox('請問你要調(diào)用哪個函數(shù)','w',c)
? ? for i in range (1,len(c)):
? ? ? ? if a==c[i]:
? ? ? ? ? ? b=enterbox('請輸入'+c[i]+'函數(shù)的參數(shù)(如果有多個參數(shù)的話請用逗號分割(a,b))')
? ? ? ? ? ? x.write(c[i]+'('+b+')')