【发布时间】:2022-02-02 22:05:32
【问题描述】:
每次运行代码时都会出现此错误 (“(”未关闭 Pylance [4,9]) 我真的找不到任何解决方案,请帮助我:( 我真的不知道该怎么做我刚开始学习py,我真的很想继续学习,所以请谁来做我的救命恩人:)
import copy
story = (
"I can't believe it's already {} ! " +
"I can't wait to put on my {} and visit every {} in my nighborhood. " +
"This year, I am going to dress up as (a) {} with {} {} . " +
"Before I {} , I make sure to grab my {} {} to hold all of my {}. " +
"Finally, all of my {} are ready to go ! " +
)
word_dict = {
'Holiday noun':['Holiday'],
'Noun':['cosplay','custom outfit','halloween clothes'],
'Place nouns':['corner','place','street'],
'Person':['Frankenstein','Princess','Queen','Cop'],
'Adjective':['creepy','shiny','lovely'],
'Body part (plural)':['arms','eye lashes','glasses'],
'Verb':['go','go out','wolk out'],
'Adjective':['little','big','colored','beautiful'],
'Noun':['bag','handbag','carryall'],
'Food':['candies','sweets','bonbons'],
'Plural noun':['things','stuff','gear'],
}
def get_word(type, local_dict):
words = local_dict[type]
cnt = len(words)-1
index = randint(0, cnt)
return local_dict[type].pop(index)
def create_story():
local_dict = copy.deepcopy(word_dict)
return story.format(
get_word('Holiday noun',local_dict),
get_word('Noun',local_dict),
get_word('Place nouns',local_dict),
get_word('Person',local_dict),
get_word('Adjective',local_dict),
get_word('Body part (plural)',local_dict),
get_word('Verb',local_dict),
get_word('Adjective',local_dict),
get_word('Noun',local_dict),
get_word('Food',local_dict),
get_word('Plural noun',local_dict),
)
print("Story 1: ")
print(create_story())
print()
print("Story 2: ")
print(create_story()) ```
【问题讨论】:
-
而不是randint,导入随机并写'random.randint',另外,你在'story'中还有一个额外的好处
标签: python random import generator pylance