Question

Python 3.7.2 for language Please comment for each line of code good naming is important 1....

Python 3.7.2 for language

Please comment for each line of code

good naming is important

1. Answer the question: what is the Python regular expression pattern that would match a hex color (https://en.wikipedia.org/wiki/Web_colors ) (for example, the pattern that would match an email address is '[\w.-]+@[\w.-]')

  1. Write an algorithm for step 3. As part of your algorithm, be sure to describe the pattern you're using to find the win/loss result for each game.
  1. Write a program that looks at the source of http://cgi.soic.indiana.edu/~dpierz/mbball.html (http://cgi.soic.indiana.edu/~dpierz/mbball.html ) (a copy of the IU men's basketball team record page). Use regular expressions to find all the games IU has played in this year and calculate the total number of wins and losses (including exhibition games)

     The output should look like the following:

Wins: 18
Losses: 12

Bonus [10 pts]. Extend your code from part 3 to also calculate the total difference in points scored in all the games (a game that finished 68-71 would have a difference of 3 points, 85-52 a difference of 33 points etc)

Total Difference: 431

Remember, as always good coding practices are part of the grade so be sure to comment your code, use good variable names, efficient regular expressions, etc.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer 1:

Regular Expression to use is:

match = re.search(r'^#(?:[0-9a-fA-F]{3}){1,2}$', str)

#Code to use

def Find_regex():
    import re
    str = '#80800' #Enter your hexadecimal
    """Check the regular expression"""
    match = re.search(r'^#(?:[0-9a-fA-F]{3}){1,2}$', str)
    if match:                    
      print ('Valid')
    else:
      print ('Invalid')
Find_regex()

Solution 2:

import re, urllib.request

"""Open the webpage"""
web_open = urllib.request.urlopen('http://cgi.soic.indiana.edu/~dpierz/mbball.html')
contents = web_open.read().decode(errors = "replace")
web_open.close()
result = []
win = 0
lose = 0
"""Use the regex"""
games_all = re.findall("(?<=div class='schedule_game_results'><div>).*?(?=</div>)", contents)
"""Calculate win lose"""
for i in games_all:
    if "W" in i:
        win += 1
    elif "L" in i:
        lose += 1
print("Wins: ", win)

print("Loses: ", lose)

points = 0
#import pdb;pdb.set_trace()
#games = games.replace(str(games[1]),'')
"""Bonus Point Question"""
for game in games_all:
    if game == games_all[1]:
        continue
    else:
        if game:
            first_score = game[2:4]
            second_score = game[5:7]
            points += abs(int(first_score) - int(second_score))
print("Total Difference: ", points)
   

Add a comment
Know the answer?
Add Answer to:
Python 3.7.2 for language Please comment for each line of code good naming is important 1....
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
  • python 3.7.2 for language good variable names please comment for each line of code 1. Answer...

    python 3.7.2 for language good variable names please comment for each line of code 1. Answer the question: when using strftime what is the placeholder that will display the full name of the day of the week (Monday, Tuesday, etc.). (ex. "%d" is the placeholder that displays the day as a two digit number) 2. Write an algorithm for step 3 3. Write a program that reads in the information from a file called ShopRecords.csv and displays all of the...

  • Please answer question 8.35 Python 3.0 for language Comment for each part of line of code...

    Please answer question 8.35 Python 3.0 for language Comment for each part of line of code explaining what is being done 8.35 A stack is a sequence container type that, like a queue, supports very restrictis methods: All insertions and removals are from one end of the stack, typicly aces the top of the stack. Implement container class Stack that implements cked to a a subclass of object, support the len) overloaded operator, and support the me be referred a...

  • In java language here is my code so far! i only need help with the extra...

    In java language here is my code so far! i only need help with the extra credit part For this project, you will create a Rock, Paper, Scissors game. Write a GUI program that allows a user to play Rock, Paper, Scissors against the computer. If you’re not familiar with Rock, Paper, Scissors, check out the Wikipedia page: http://en.wikipedia.org/wiki/Rock-paper-scissors This is how the program works: The user clicks a button to make their move (rock, paper, or scissors). The program...

  • Python 3.7.2 (Please comment on code and post screenshot of your source code. Thanks) class1: Part 1 You just finished administering the final exam for all of the students in the "Introduction t...

    Python 3.7.2 (Please comment on code and post screenshot of your source code. Thanks) class1: Part 1 You just finished administering the final exam for all of the students in the "Introduction to Computer Programming classes this semester. The exam was a 25 question multiple choice exam, and it is your job to grade the exams. You have all of the scores stored in a series of text files (click here to download these files). To begin, download the data...

  • 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...

  • Chapter overview 1. Reasons for international trade Resources reasons Economic reasons Other reasons 2. Difference between...

    Chapter overview 1. Reasons for international trade Resources reasons Economic reasons Other reasons 2. Difference between international trade and domestic trade More complex context More difficult and risky Higher management skills required 3. Basic concept s relating to international trade Visible trade & invisible trade Favorable trade & unfavorable trade General trade system & special trade system Volume of international trade & quantum of international trade Commodity composition of international trade Geographical composition of international trade Degree / ratio of...

  • Please read the article and answer about questions. You and the Law Business and law are...

    Please read the article and answer about questions. You and the Law Business and law are inseparable. For B-Money, the two predictably merged when he was negotiat- ing a deal for his tracks. At other times, the merger is unpredictable, like when your business faces an unexpected auto accident, product recall, or government regulation change. In either type of situation, when business owners know the law, they can better protect themselves and sometimes even avoid the problems completely. This chapter...

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