Python Forum
Function help - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Function help (/thread-13704.html)



Function help - csascott - Oct-28-2018

def suggest(product_idea):
                          return product_idea + "inator"
                 

How would I raise a value error? Exact inructions below.I have tried everything!







I've made a function that creates brand new product names using "artificial intelligence".
I have a problem though, people keep on adding product ideas that are too short. It makes the suggestions look bad.
Can you please raise a ValueError if the product_idea is less than 3 characters long? product_idea is a string.
string.



RE: [b]Function help[/b] - Mekire - Oct-28-2018

Please do not style your post like that. Post normally using code tags around code.

As for your question something like:
if len(product_idea) < 3:
    raise ValueError
Seems to be what you want.