Python Forum
Homework Problem - 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: Homework Problem (/thread-13687.html)



Homework Problem - csascott - Oct-27-2018

My nam is Chris. I use Python 3.7 on a mac. I am in boot camp and online school. My mac os system is mohave. I have been learning programing for 3 weeks now. Here were my directions:

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. Thanks in advance!

[Python] def suggest(product_idea):
return product_idea + "inator"[Python}



I have tried many things and have run out of ideas?
Thank You,
Chris


RE: Homework Problem - scidam - Oct-27-2018

Hi, Chris!

I'm not sure that I have understood you correctly, but
raising an exception is quite simple in Python, e.g.

def suggest(product_idea):
    if len(product_idea) <= 3:
        raise ValueError('The string has too low length (# of chars should be > 3). ')
    #  do some stuff if needed
    return product_idea + "etc... "