Question: Subtask 1 . 3 : Extract the description of a product Write a function extract _ description ( product _ card ) that takes a
Subtask : Extract the description of a product
Write a function extractdescriptionproductcard 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, productcards contains newlines.
def extractdescriptionproductcard:
IN: productcard, string, the product card string
OUT: description, string, the description
# find p tag with class description
pattern YourCodeHere
res researchpattern productcard
if res is None:
raise ValueErrorNo description found in the product card"
# access the captured description
description res.group
# return the description
return description
if namemain:
description extractdescriptionproductcards
printdescription
Expected output:
extractdescriptionproductcards
"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 fouryear journey to eternal rest. But there's trouble in paradise. Help Manny untangle himself from a conspiracy that threatens his very salvation. LucasArts
extractdescriptionproductcards
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."
extractdescriptionproductcards
A gothic suspense tale set in a cursed mansion. 'The House in Fata Morgana' is a fulllength visual novel spanning nearly a millennium that deals in tragedy, human nature, and insanity. This version includes three games and more:
: The House in Fata Morgana: the main storyline.
: A Requiem for Innocence: a prequel shedding light on the origins of Fata Morgana's terrible curse.
: Reincarnation: a sequel featuring the central cast members reincarnated in the present day. The part including voices
: Other additional short stories."""
You should return the price in decimal places, eg means euros.
def extractpriceproductcard:
IN: productcard, string, the product card string
OUT: pricedecimal, int, the price in decimal places, eg means euros
# find div tag with class pricewrapper
pattern YourCodeHere
res researchpattern productcard
# access the captured price
price res.group
if res is None:
raise ValueErrorNo price found in the product card"
# convert the price to an integer
pricedecimal YourCodeHere
# return the price
return pricedecimal
if namemain:
price extractpriceproductcards
printprice
Expected output: Expected output:
extractpriceproductcards
extractpriceproductcards
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
