Question

This assignment should be written in PYTHON programming language Please write python programs to answer the...

This assignment should be written in PYTHON programming language

Please write python programs to answer the following questions. Everything should be dynamically scraped from the live websites using the Beautiful Soup interface.

Texas Dept of Criminal Justice (relevant url: http://www.tdcj.state.tx.us/death_row/dr_executions_by_year.html): Accept two integers as input. You can assume that these values represent a valid starting and ending year within the range of the years in the table. Process the html and find the total number of executions in Texas between the starting year and the ending year (inclusive of the start and end years).

Example:
Enter starting year: 1990
Enter ending year: 2000
Total executions: 206
0 0
Add a comment Improve this question Transcribed image text
Answer #1
import requests
from bs4 import BeautifulSoup

page = requests.get('https://www.tdcj.texas.gov/death_row/dr_executions_by_year.html')


soup = BeautifulSoup(page.text, 'html.parser')
rows = soup.select('.overflow table tr')[1:-1]

executions = {}

for link in rows:
    x = link.find('th')
    y = link.findAll('td')[-2]
    executions[int(x.text)] = int(y.text)

#print(executions)

start = int(input('Enter starting year: '))
end = int(input('Enter ending year: '))
total = 0
for y in range(start, end + 1):
    if y in executions:
        total += executions[y]
print('Total executions:', total)


Hi. please find the answer above.. i have given comments so that it is very easy for you to understand the flow. In case of any doubts, please ask in comments. If the answer helps you, please upvote. Thanks!

Add a comment
Know the answer?
Add Answer to:
This assignment should be written in PYTHON programming language Please write python programs to answer the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • You need not run Python programs on a computer in solving the following problems. Place your...

    You need not run Python programs on a computer in solving the following problems. Place your answers into separate "text" files using the names indicated on each problem. Please create your text files using the same text editor that you use for your .py files. Answer submitted in another file format such as .doc, .pages, .rtf, or.pdf will lose least one point per problem! [1] 3 points Use file math.txt What is the precise output from the following code? bar...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT