# Read books info from books.xml and display title and price
from bs4 import BeautifulSoup

f = open("books.xml", "rt")
bs = BeautifulSoup(f.read(), 'xml')
f.close()

print('Subject : ', bs.subject.attrs['title'])
books = bs.subject.find_all("book")

for book in books:
    title = book.find("title").text
    price = book.find("price").text
    print(f"{title:30} {int(price):5}")

d7f6c00b983a22c6cc689af172458ee32ca48521
<mask token>

<mask token>
f.close()
print('Subject : ', bs.subject.attrs['title'])
<mask token>
for book in books:
    title = book.find('title').text
    price = book.find('price').text
    print(f'{title:30} {int(price):5}')

<mask token>
f = open('books.xml', 'rt')
bs = BeautifulSoup(f.read(), 'xml')
f.close()
print('Subject : ', bs.subject.attrs['title'])
books = bs.subject.find_all('book')
for book in books:
    title = book.find('title').text
    price = book.find('price').text
    print(f'{title:30} {int(price):5}')

from bs4 import BeautifulSoup
f = open('books.xml', 'rt')
bs = BeautifulSoup(f.read(), 'xml')
f.close()
print('Subject : ', bs.subject.attrs['title'])
books = bs.subject.find_all('book')
for book in books:
    title = book.find('title').text
    price = book.find('price').text
    print(f'{title:30} {int(price):5}')

# Read books info from books.xml and display title and price
from bs4 import BeautifulSoup

f = open("books.xml", "rt")
bs = BeautifulSoup(f.read(), 'xml')
f.close()

print('Subject : ', bs.subject.attrs['title'])
books = bs.subject.find_all("book")

for book in books:
    title = book.find("title").text
    price = book.find("price").text
    print(f"{title:30} {int(price):5}")
