Commit d3743419 authored by Recolic K's avatar Recolic K

make the noob code better

parent d916148e
......@@ -12,12 +12,10 @@ def loadJson(fileName):
return json.loads(file.read())
data = loadJson("data.json")
motto_data = data["famous"] # a 代表prefix_data,b代表postfix_data
prefix_data = data["before"] # 在motto_data前面弄点nonsense_data
postfix_data = data['after'] # 在motto_data后面弄点nonsense_data
nonsense_data = data['bosh'] # 代表文章主要nonsense_data来源
xx = "学生会退会"
famous_data = list(data['famous']) # a 代表prefix_data,b代表postfix_data
prefix_data = list(data['before']) # 在famous_data前面弄点nonsense_data
postfix_data = list(data['after' ]) # 在famous_data后面弄点nonsense_data
nonsense_data = list(data['bosh' ]) # 代表文章主要nonsense_data来源
repeat_factor = 2
......@@ -30,14 +28,14 @@ def randomized_yield(iterable):
yield ele
nonsense_generator = randomized_yield(nonsense_data)
motto_generator = randomized_yield(motto_data)
famous_generator = randomized_yield(famous_data)
def new_motto():
global motto_generator
xx = next(motto_generator)
xx = xx.replace("a", random.choice(prefix_data) )
xx = xx.replace("b", random.choice(postfix_data) )
return xx
def new_famous():
global famous_generator
famous = next(famous_generator)
famous = famous.replace("a", random.choice(prefix_data) )
famous = famous.replace("b", random.choice(postfix_data) )
return famous
def new_paragraph():
xx = ". "
......@@ -46,16 +44,15 @@ def new_paragraph():
return xx
if __name__ == "__main__":
xx = input("请输入文章主题:")
for x in xx:
tmp = str()
while ( len(tmp) < 6000 ) :
randsrc = random.randint(0,100)
if randsrc < 5:
tmp += new_paragraph()
elif randsrc < 20 :
tmp += new_motto()
else:
tmp += next(nonsense_generator)
tmp = tmp.replace("x",xx)
print(tmp)
topic = input("请输入文章主题:")
result = str()
while ( len(result) < 6000 ) :
randsrc = random.randint(0,100)
if randsrc < 5:
result += new_paragraph()
elif randsrc < 20 :
result += new_famous()
else:
result += next(nonsense_generator)
result = result.replace("x",topic)
print(result)
......@@ -164,4 +164,4 @@
"曾经提到过",
"说过一句富有哲理的话"
]
}
\ No newline at end of file
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment