Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please use Python! Part A (20 points) The code below is intended to model a PIC student who attends OH and uses what they learn

Please use Python!

Part A (20 points)

The code below is intended to model a PIC student who attends OH and uses what they learn to do better on future homework assignments. There are several functions intended to model this student's actions. The docstring correctly states the intended functionality of the class, but the code itself does not necessarily implement the docstring correctly.

----------------------

import random

class PICStudent: """ A class representing a PIC student. Includes the following instance variables: - name (string), the name of the student. - understanding (int or float), the student's understanding of Python. Includes the following methods: - add_name(), sets a user-specified value of name for the student. No return value. - say_hi(), prints a message containing the student's name. - go_to_OH(), increases the student's understanding by one unit. No return value. - do_HW(), returns a score (int or float) out of 100 based on the student's understanding of Python. """ pass

def add_name(PCS, name): if type(PCS) != PICStudent: raise TypeError("This function is designed to work with objects of class PICStudent") PCS.name = name

def say_hi(PCS, name): print("Hello! My name is " + str(self.name))

def go_to_OH(PCS): if type(PCS) != PICStudent: raise TypeError("This function is designed to work with objects of class PICStudent") PCS.understanding += 1 def do_HW(PCS): if type(PCS) != PICStudent: raise TypeError("This function is designed to work with objects of class PICStudent") score = max(75+25*random.random(), 25*PCS.understanding) return score

-------------------

First, critique this solution. For full credit, state four (4) distinct issues in this code. Your issues should include one of each of the following types:

  • One way in which the code does not match the docstring.
  • One way in which an unexpected exception could be raised.
  • One way in which the code might give an illogical or absurd output without raising an exception.
  • One additional issue. This could be a second instance of one of the above categories, or an issue of a completely different type.

There may be some overlap between these types of issues. For example, an illogical or absurd output could also be in contradiction of the docstring. In such a case, you can choose which category in which to count the issue, but must still describe a total of four distinct issues.

Feel free to add code cells as needed to demonstrate your critiques.

Double click this cell and write your critique.

Second, improve the code. Write a modified version that (a) fully matches the supplied docstring and (b) fixes the issues that you indicated above. It is not necessary to add new docstrings, even if the old ones are no longer appropriate due to your changes. It is not necessary to demonstrate your code, although doing so may help us give you partial credit.

# your improvement

image text in transcribed

Please use Python!

Part A (20 points) The code below is intended to model a PIC student who attends OH and uses what they learn to do better on future homework assignments. There are several functions intended to model this student's actions. The docstring correctly states the intended functionality of the class, but the code itself does not necessarily implement the docstring correctly. In [1]: inport random class PICStudent: A class representing a PIC student. Includes the following instance variables: - name (string), the name of the student. - understanding (int or float), the student's understanding of Python. Includes the following methods: - add_name(), sets a user-specified value of name for the student. No return value. - say_hi (), prints a message containing the student's name. - go_to_OHO, increases the student's understanding by one unit. No return value. - do_HYO, returns a score (int or float) out of 100 based on the student's understanding of Python. pass def add_name (PCs, name) : if type (PCS) != PICStudent: raise TypeError("This function is designed to work with objects of class PICStudent") PCS. name = name def say_hi (PCs, name) : print("Hello! My name is " + str(self.name)) def go_to_OH (PCS) : if type (PCS) != PICStudent: raise TypeError("This function is designed to work with objects of class PICStudent') PCS. understanding += 1 def do_HW (PCS) : if type (PCS) != PICStudent: raise TypeError("This function is designed to work with objects of class PICStudent') score = max(75+25#random. random 0), 25*PCS. understanding) return score

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_2

Step: 3

blur-text-image_3

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

Professional Visual Basic 6 Databases

Authors: Charles Williams

1st Edition

1861002025, 978-1861002020

More Books

Students also viewed these Databases questions

Question

2. Why has the conflict escalated?

Answered: 1 week ago

Question

1. What might have led to the misinformation?

Answered: 1 week ago