Question: Subtask 1 . 3 : Extract the description of a product Write a function extract _ description ( product _ card ) that takes a

Subtask 1.3: Extract the description of a product
Write a function extract_description(product_card) that takes a product card string as input and returns the description as a string.
Note: The description may contain newlines and special characters. For example, product_cards [6] contains newlines.
```
def extract_description(product_card):
"""
IN: product_card, string, the product card string
OUT: description, string, the description
"""
# find p tag with class `description`
pattern ="""__Your_Code_Here__"""
res = re.search(pattern, product_card)
if res is None:
raise ValueError("No description found in the product card")
# access the captured description
description = res.group(1)
# return the description
return description
```
```
if __name__=="__main__":
description = extract_description(product_cards[6])
print(description)
``` Expected output:
> extract_description(product_cards[-1])
"Something's rotten in the Land of Dead and you're being played for a sucker. Meet Manny Calavera, travel agent at the Department of Death. He sells luxury packages to souls on their four-year journey to eternal rest. But there's trouble in paradise. Help Manny untangle himself from a conspiracy that threatens his very salvation. [LucasArts]"
> extract_description(product_cards[0])
"As a young boy, Link is tricked by Ganondorf, the King of the Gerudo Thieves. The evil human uses Link to gain access to the Sacred Realm, where he places his tainted hands on Triforce and transforms the beautiful Hyrulean landscape into a barren wasteland. Link is determined to fix the problems he helped to create, so with the help of Rauru he travels through time gathering the powers of the Seven Sages."
> extract_description(product_cards[6])
""A gothic suspense tale set in a cursed mansion. 'The House in Fata Morgana' is a full-length visual novel spanning nearly a millennium that deals in tragedy, human nature, and insanity. This version includes three games and more:
1: The House in Fata Morgana: the main storyline.
2: A Requiem for Innocence: a prequel shedding light on the origins of Fata Morgana's terrible curse.
3: Reincarnation: a sequel featuring the central cast members reincarnated in the present day. *The part including voices
4: Other additional short stories."""
- You should return the price in 2 decimal places, e.g.,9199 means 91.99 euros.
```
def extract_price(product_card):
"""
IN: product_card, string, the product card string
OUT: price_2decimal, int, the price in 2 decimal places, e.g.,9199 means 91.99 euros
"""
# find div tag with class `price-wrapper`
pattern ="""__Your_Code_Here__"""
res = re.search(pattern, product_card)
# access the captured price
price = res.group(1)
if res is None:
raise ValueError("No price found in the product card")
# convert the price to an integer
price_2decimal ="""__Your_Code_Here__"""
# return the price
return price_2decimal
if __name__=="__main__":
price = extract_price(product_cards[-1])
print(price)
```
Expected output: Expected output:
```
> extract_price(product_cards[-1])
9199
> extract_price(product_cards[0])
9199
```
Subtask 1 . 3 : Extract the description of a

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!