在Python中解析时意外的EOF随机语句生成器

问题描述:

我正在运行没有扩展名的Python 2.7.12。这是我的代码,并且在解析时遇到意外的EOF。在Python中解析时意外的EOF随机语句生成器

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() 

如果您可以提供帮助,并且是的话,我会'接受',如果您想要一些信誉的话。

您的身份已关闭;有正确的缩进(缩写所有列表,以提高知名度...):

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

谢谢,这工作得很好! –