Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2) We've been talking a bit recently about what makes good code and what makes a code smell or not 'clean code'. a) 20pts) The

image text in transcribedimage text in transcribed

2) We've been talking a bit recently about what makes good code and what makes a "code smell or not 'clean code'. a) 20pts) The code below is smelly all right. Tell me everything that is wrong with it, especially in light of what we have talked about in class. def. nl first half (self) questionl - input("Does your team's state begin with a letter from A-M? (y): *) while not (question. lower().startswith('y') or question1. lower().startswith('n')): print("Please answer 'yes' or 'no'.") questionl - input ("Does your team's state begin with a letter from A-M? (y): ") if question1. lower().startswith('y'): self.nl_teams = self.nl_teams[:8] #remove the last half print (self.nl teams) question2 - input("Does your team's logo have a lot of red? (y): ") while not (question2. lower().startswith('y') or question2. lower().startswith('n')): print("Please answer 'yes' or 'no'.") question2 - input ("Does your team's logo have a lot of red? (y): ") if question2. lower().startswith('y'): self.nl_teams - self.nl_teams[:4] * remove the last half of the remaining print(self.nl_teams) question3 - input("Does your team's state start with the letter 'A'? (y): ") while not (question3.lower().startswith('y') or question3.lower().startswith('n')): print("Please answer 'yes' or 'no'.) question3 - input ("Does your team's state start with the letter 'A'? (y): ") if question3.lower().startswith('y'): self.nl_teams = self.nl_teams[:2] #remove the last half of the remaining teams print (self.nl_teams) question4 = input("Is your team the Braves? (y): ") while not (question. lower().startswith("y') or question.lower().startswith('n')): print("Please answer 'yes' or 'no'.") question4 - input("Is your team the Braves? (y): ") if question4. lower().startswith('y'): self.nl_teams = self.nl_teams[-1:] #keep the braves print("your team is the braves") print(self.nl_teams) else: self.nl_teams = self.nl_teams[:1] #keep the diamondbacks print("your team is the Diamondbacks!") print(self.nl_teams) else: #if it doesn't begin with 'A' self.nl_teams = self.nl_teams (-2:] print(self.nl_teams) print(self.nl teams) questions - input("is your team the Cubs? (y): ") while not (questions. lower().startswith('y') or question5. lower().startswith('n')): print("Please answer 'yes' or 'no'.") questions - input("is your team the Cubs? (y): -) if questions. lower().startswith('y'): self.nl teams = self.nl teams[:1] print("your team is the cubs") print(self.nl_teams) else: self.nl_teams = self.nl_teams [-1:] print("your team is the Reds") print(self.nl_teams) else: self.nl_teams = self.nl_teams[ -4:] print(self.nl_teams) question6 = input ("Does your team's state start with the latter 'M'? (y): "); while not (question. Lower().startswith('y') or question6. lower().startswith('n')): B) (20pts) refactor this code (ok gk it is so terrible it might be a rewrite) to do the same thing, but follow the rules of thumb for clean code a bit better. 2) We've been talking a bit recently about what makes good code and what makes a "code smell or not 'clean code'. a) 20pts) The code below is smelly all right. Tell me everything that is wrong with it, especially in light of what we have talked about in class. def. nl first half (self) questionl - input("Does your team's state begin with a letter from A-M? (y): *) while not (question. lower().startswith('y') or question1. lower().startswith('n')): print("Please answer 'yes' or 'no'.") questionl - input ("Does your team's state begin with a letter from A-M? (y): ") if question1. lower().startswith('y'): self.nl_teams = self.nl_teams[:8] #remove the last half print (self.nl teams) question2 - input("Does your team's logo have a lot of red? (y): ") while not (question2. lower().startswith('y') or question2. lower().startswith('n')): print("Please answer 'yes' or 'no'.") question2 - input ("Does your team's logo have a lot of red? (y): ") if question2. lower().startswith('y'): self.nl_teams - self.nl_teams[:4] * remove the last half of the remaining print(self.nl_teams) question3 - input("Does your team's state start with the letter 'A'? (y): ") while not (question3.lower().startswith('y') or question3.lower().startswith('n')): print("Please answer 'yes' or 'no'.) question3 - input ("Does your team's state start with the letter 'A'? (y): ") if question3.lower().startswith('y'): self.nl_teams = self.nl_teams[:2] #remove the last half of the remaining teams print (self.nl_teams) question4 = input("Is your team the Braves? (y): ") while not (question. lower().startswith("y') or question.lower().startswith('n')): print("Please answer 'yes' or 'no'.") question4 - input("Is your team the Braves? (y): ") if question4. lower().startswith('y'): self.nl_teams = self.nl_teams[-1:] #keep the braves print("your team is the braves") print(self.nl_teams) else: self.nl_teams = self.nl_teams[:1] #keep the diamondbacks print("your team is the Diamondbacks!") print(self.nl_teams) else: #if it doesn't begin with 'A' self.nl_teams = self.nl_teams (-2:] print(self.nl_teams) print(self.nl teams) questions - input("is your team the Cubs? (y): ") while not (questions. lower().startswith('y') or question5. lower().startswith('n')): print("Please answer 'yes' or 'no'.") questions - input("is your team the Cubs? (y): -) if questions. lower().startswith('y'): self.nl teams = self.nl teams[:1] print("your team is the cubs") print(self.nl_teams) else: self.nl_teams = self.nl_teams [-1:] print("your team is the Reds") print(self.nl_teams) else: self.nl_teams = self.nl_teams[ -4:] print(self.nl_teams) question6 = input ("Does your team's state start with the latter 'M'? (y): "); while not (question. Lower().startswith('y') or question6. lower().startswith('n')): B) (20pts) refactor this code (ok gk it is so terrible it might be a rewrite) to do the same thing, but follow the rules of thumb for clean code a bit better

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David M. Kroenke

12th Edition International Edition

1292023422, 978-1292023427

More Books

Students also viewed these Databases questions

Question

What is the role of U.S states in regulating investment banks?

Answered: 1 week ago

Question

What is the source of AFP?

Answered: 1 week ago

Question

What is the purpose of the Salary Structure Table?

Answered: 1 week ago

Question

What is the scope and use of a Job Family Table?

Answered: 1 week ago