+ 2

When I am running this code,this code give me error. Please tell me why? I am confused now.😓

def show_item(categories,*items): print("categories:"+items) for item in items: print(item) show_item("monitor","mobile","television")

31st Aug 2024, 5:46 AM
Amitesh Yadav
Amitesh Yadav - avatar
7 Respostas
+ 8
In future, please link to your code in the playground. By pasting in the question, you may introduce new errors. You may even disguise errors which we can only guess. For the given code there are indentation errors. Lines 3 and 4 are currently outside of the method body. Also, you cannot concatenate a string with a tuple. Perhaps, you want a string representation of the tuple: print("categories:" + str(items))
31st Aug 2024, 5:55 AM
Ani Jona 🕊
Ani Jona 🕊 - avatar
+ 4
Amitesh Yadav , besides the already mentioned issues, some questions raise up for me: > since you did not provide an input / output sample or a task description, the purpose of your code is not quite clear. > you pass 3 string items when calling the function `show_item()`. the function has 2 parameters to store the 3 items: `categories` -> a string: 'monitor' `items` -> a tuple of strings: ('mobile', 'television') why is this done this way? we can just use *one* data container to take all of the items passed by the caller. using: def show_item(*items): will result in: -> tuple of strings: ('monitor', 'mobile', 'television') now you can do whatever you like with the items...
31st Aug 2024, 8:35 AM
Lothar
Lothar - avatar
+ 3
Thanks bro. It help me a lot ☺️😊😊
31st Aug 2024, 6:41 AM
Amitesh Yadav
Amitesh Yadav - avatar
+ 3
def show_item(category, *items): print("Category:", category) for item in items: print(item) show_item("Electronics", "monitor", "mobile", "television")
31st Aug 2024, 4:27 PM
Oleksiy Semyanyk
Oleksiy Semyanyk - avatar
+ 1
You're welcome :)
31st Aug 2024, 6:50 AM
Ani Jona 🕊
Ani Jona 🕊 - avatar
+ 1
Father Cubans cost they adding furniture and Pro
1st Sep 2024, 9:49 PM
ชัยรัตน์ โกฎิลออง
ชัยรัตน์ โกฎิลออง - avatar
0
With anime gaining popularity worldwide, there is an increasing need for localized content that resonates with diverse cultural contexts. The AI anime generator tool can be used to create characters, environments, and narratives tailored to specific regions or cultures. For example, creators can produce anime that reflects local folklore, societal themes, or cultural aesthetics, ensuring that content is both globally appealing and locally relevant. This localization capability enhances cross-cultural understanding and appreciation while also providing a more personalized experience for global audience s https://airbrush.com/ru/ai-anime-generator .
9th Sep 2024, 9:57 AM
Debin Alsa
Debin Alsa - avatar