联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp

您当前位置:首页 >> CS作业CS作业

日期:2024-04-04 06:56

Course Title: Python I

Quiz 2: Classes and Object Oriented Programming in Python

If you want to do use Colab or Jupiter notebook, please submit your .ipynb file with the file name using your student ID

A. Write a Python line that instantiates an object myvehicle of class Vehicle, setting its type attribute to "car" and color attribute to "blue" directly upon creation, without modifying the class definition.

Solution with output:

Hints: Add screenshots of your codes and output here

Sample screenshot of code and results

B. Given a Rectangle class for area calculation, create a Square subclass that inherits from Rectangle but initializes with a single side length. Override the __init__ using super() and add a describe() method in Square to output "Square with side: x", where x is the square's side. Demonstrate by instantiating a Square and calling describe().

Solution with output:

Hints: Add screenshots of your codes and output here

C. In "Breaking Bad," the unique meth formula was crucial to Walter White and Jesse Pinkman's success. Replicate this by securing a secret formula within a Python class SecretFormula, using a private attribute __formula with the value "C10H15N". Implement a class method reveal_formula(cls, passphrase) to disclose the formula only when the correct passphrase "Heisenberg" is used; otherwise, it responds with "Nice try!" Show how to access this formula with both correct and incorrect passphrases. 

Solution with output:

Hints: Add screenshots of your codes and output here 

D. Design a CrossoverEvent data class to monitor a joint event for "Sherlock" and "Doctor Who" characters, including the event name, participants, and outcome. Incorporate type hints and a method to modify the event's result. Initiate the class with "The Time Detective" event, starring "Sherlock Holmes" and "The Doctor," starting with an "In Progress" outcome. Finally, update the status to "Successfully Solved."

Solution with output:

Hints: Add screenshots of your codes and output here

 

 


版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp