python随机生成中文句子_在Python随机句生成器中解析时发生意外的EOF

I am running Python 2.7.12 with no extensions. This is my code, and I am getting an Unexpected EOF while parsing.

import random

import sys

import time

print("Welcome to the weird sentence generator.")

wantto = True

print("Press enter to generate a weird sentence. Press Q to quit.")

while True:

senttype = random.randint(1,5)

VERBS = ["dying", "farting","eating","pooping","pooing","drinking","running","walking","dancing","singing","learning","burping","digesting","fighting","licking","flying","smoking","mating","reproducing","playing","thinking","peeing","typing","programming","sitting","standing","slipping","ice-skating","skating","riding","murdering","killing","snoring","watching","looking","sprinting","jogging","opening","closing","calling","drawing","painting","washing","cleaning","cooking","kissing","snogging","showering","bathing","lifting","listening","conjuring","writing","composing","socializing","talking","lip-syncing to music.ly","being annoying","wrestling","practicing martial art","meeting people","skateboarding","riding a bike","proposing to his girlfriend","trying to get good at Game of War because he kept getting rekt by TheLegend27","clicking stuff on his PC","clicking his tongue","whistling","clapping","helping someone kill themself","failing to think of examples for this random sentence program"]

verb = random.choice(VERBS)

VERBSTWO = ["die","fart","eat","poop","poo","drink","run","walk","dance","sing","learn","flirt","digest","fart","eat","fly","burp","dig","smoke","lick","snore","kiss","snog","vomit","throw up","play","think","pee","type","arrest","program","sit","stand","lie down","slip","ice-skate","skate","skateboard","ride","murder","kill","slaughter","snore","watch","look","sprint","jog","open","close","call","drag","draw","paint","photograph","wash","clean","cook","bathe","solve"]

NOUNS = ["pig","cow","chicken","camel","man","woman","girl","boy","mouse","house","box","computer","fox","omelette","egg","sandwich","mouse pad","remote control","TV remote","screen","frame","statue","painting","wall","floor","ceiling","window","table","chair","TV","xBox 360","Wii","Playstation 1","Playstation 2","Playstation 3","Playstation 4","xBox 1","Nintendo DS","Game Boy","Nintendo 3DS","charger","phone","telephone","iPhone","iPad","iPod","flower","tree","bush","president","prime minister","baby","mirror","cupboard","wardrobe","walrus","goat","koala","sea lion","fish","goldfish","DVD","DVD player","USB","bed","bedroom","toilet","bathroom","living room","room","kitchen","oven","fridge","freezer","gate","snake","python","document","sentence","windowsill","shower","dining room","napkin","fork","knife","spoon","sugar cube","sugar","salt","potato","carrot","cucumber","tomato","soup","vinegar","crisp","chip","French fry","egg","pillow","blanket","matress","sheet","file","user","rapper","singer","runner","builder","zombie","wizard","engineer","monkey","gorilla","baboon","skeleton","tiger","pop star"]

noun = random.choice(NOUNS)

ADVERBS = ["slowly","quickly","stupidly","cleverly","harshly","horribly","beautifully","skillfully","easily","difficultly","nicely","pleasantly","surprisingly","prettily","artfully","craftily","hungrily","thirstily","greedily","selfishly","unselfishly","kindly","generously","randomly","idiotically","periodically","logically","illogically","controversially","sickeningly","poorly"]

adverb = random.choice(ADVERBS)

ADJECTIVES = ["fat","thin","weird","strange","normal","average","random","legendary","horrible","vile","cruel","ugly","pretty","beautiful","disgusting","pleasant","surprising","nice","artful","pretty","crafty","hungry","thirsty","greedy","selfish","unselfish","kind","generous","thorough","idiotic","stupid","obese","logical","illogical","controversial","sickening","poor","dumb"]

adjective = random.choice(ADJECTIVES)

adjective2 = random.choice(ADJECTIVES)

noun2 = random.choice(NOUNS)

COLOURS = ["blue","green","maroon","yellow","pink","purple","white","black","brown","hazel","red","orange","turquoise","peach","tan","chestnut","chocolate"]

colour = random.choice(COLOURS)

verb2 = random.choice(VERBSTWO)

what = input()

if senttype == 1:

print("The",noun,"was",adverb,verb,"in the",adjective,"park, but the", adjective2,colour,noun2,"wanted him to", verb2+".")

if senttype == 2:

print("My favourite",noun,"is the",adjective,colour,"one",adverb,verb,"in a",noun2+"!")

if senttype == 3:

print("I",verb2,"with a",adjective,noun,"frequently and",adverb+".")

if senttype == 4:

print("Although",verb,"is",adjective+", the",noun,"was too",adjective2,"to",verb2,"it.")

if senttype == 5:

print("The",adjective,colour,noun,"is good at",verb,"and likes to",adverb,verb2,"every day!")

if what =="Q" or what == "q":

sys.exit()

Thanks if you could help, and yes, I will 'accept' answers if you want some reputation.

解决方案

your identation was off; there the correct indentation (abbreviated all your lists to increase visibility...):

import random

import sys

import time

print("Welcome to the weird sentence generator.")

wantto = True

print("Press enter to generate a weird sentence. Press Q to quit.")

while True:

senttype = random.randint(1,5)

VERBS = ["dying", ...,"failing to think of examples for this random sentence program"]

verb = random.choice(VERBS)

VERBSTWO = ["die",...,"solve"]

NOUNS = ["pig",...,"pop star"]

noun = random.choice(NOUNS)

ADVERBS = ["slowly",...,"poorly"]

adverb = random.choice(ADVERBS)

ADJECTIVES = ["fat",...,"dumb"]

adjective = random.choice(ADJECTIVES)

adjective2 = random.choice(ADJECTIVES)

noun2 = random.choice(NOUNS)

COLOURS = ["blue"...,"chocolate"]

colour = random.choice(COLOURS)

verb2 = random.choice(VERBSTWO)

what = input('waiting for input')

if senttype == 1:

print("The",noun,"was",adverb,verb,"in the",adjective,"park, but the", adjective2,colour,noun2,"wanted him to", verb2+".")

if senttype == 2:

print("My favourite",noun,"is the",adjective,colour,"one",adverb,verb,"in a",noun2+"!")

if senttype == 3:

print("I",verb2,"with a",adjective,noun,"frequently and",adverb+".")

if senttype == 4:

print("Although",verb,"is",adjective+", the",noun,"was too",adjective2,"to",verb2,"it.")

if senttype == 5:

print("The",adjective,colour,noun,"is good at",verb,"and likes to",adverb,verb2,"every day!")

if what =="Q" or what == "q":

break

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值