Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Homework Problem
#1
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
Reply
#2
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... "
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  problem with a formula 1 kind of homework claroque 2 1,412 Jun-20-2023, 09:58 PM
Last Post: claroque
  Bakery Problem.. Can you Help My Homework Cemvrs 1 2,360 Jan-14-2022, 05:47 PM
Last Post: Yoriz
  Need help with a homework problem on logical operators voodoo 3 4,593 Jun-28-2019, 03:45 PM
Last Post: jefsummers
  Homework Problem Travisbulls34 1 2,949 Sep-11-2018, 04:04 PM
Last Post: ichabod801
  Help with homework problem - iterating a function midnitetots12 4 3,497 Feb-21-2018, 10:51 PM
Last Post: nilamo
  Problem with a homework Samuelcu 2 2,836 Feb-03-2018, 01:39 PM
Last Post: Samuelcu
  Homework problem Dem_Prorammer 1 3,796 May-20-2017, 07:49 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020