i get this error everytime i run my code ( "(" was not closed Pylance [4,9] ) and i really can't find any solution for it guys please help me :( and i really don't know what to do i just started learning py and i really wanna keep going so who's please going to be my saver :)
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()) ```
If you execute your code, it will tell where the first non-excepted character is:
python .\nietchez.py
File "C:\Users\nietchez\source\nietchez.py", line 9
)
^
SyntaxError: invalid syntax
So there is something wrong right before the )
. Remove the +
sign, and also, add the random library:
import copy
from random import randint
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 ! "
)
Furthermore, you don't even need the +
between the lines:
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 {} {} . 1"
"Before I {} , I make sure to grab my {} {} to hold all of my {}. "
"Finally, all of my {} are ready to go ! "
)