Question

Exercise: create01 Description Write a function that receives no parameters and returns a Pencil object constructed with 3 le

Python Language need help asap

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

Answer

Pencil.py

class Pencil():
def __init__(self,num_leads,lead_length):
self.num_leads=num_leads
self.lead_length=lead_length
def get_num_leads(self):
return self.num_leads
def get_current_lead_length(self):
return self.lead_length

Screenshot with correct indendation

2 3 4 5 6 7. 8 class Pencil(): _init__(self,num_leads, lead_length): self.num_leads=num_leads self.lead_length=lead_length de

Test.py

import Pencil
def create01():
return Pencil.Pencil(3,10)
p=create01()
print(p.get_num_leads())
print(p.get_current_lead_length())

Screenshot with correct indendation

1 import Pencil 2. def create01(): 3 return Pencil.Pencil(3,10) 4 p=create01() 5 print(p.get_num_leads()) 6 print(p.get_curre

Output

3 10

This program can also be written as single one

1. class Pencil(): 2 def __init__(self, num_leads, lead_length): 3 self.num_leads=num_leads 4 self.lead_length=lead_length 5

If you find this answer useful , please rate positive, thankyou

2 3 4 5 6 7. 8 class Pencil(): _init__(self,num_leads, lead_length): self.num_leads=num_leads self.lead_length=lead_length def get_num_leads(self): return self.num_leads def get_current_lead_length(self): return self.lead_length

1 import Pencil 2. def create01(): 3 return Pencil.Pencil(3,10) 4 p=create01() 5 print(p.get_num_leads()) 6 print(p.get_current_lead_length())

3 10

Add a comment
Know the answer?
Add Answer to:
Python Language need help asap Exercise: create01 Description Write a function that receives no parameters and...
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
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