本文介绍了在Python随机句发生器中进行解析时发生意外的EOF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在运行没有扩展的Python 2.7.12.这是我的代码,解析时出现意外的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
这篇关于在Python随机句发生器中进行解析时发生意外的EOF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!