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
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
Output
This program can also be written as single one
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
Python Language need help asap Exercise: create01 Description Write a function that receives no parameters and...
pYTHON Exercise: create01 Description Write a function that receives no parameters and returns a Pencil object constructed with 3 leads. Function Name create01 Parameters • None Return Value A Pencil object with 3 leads. Example р create01() print(p.get_num_leads()) # -> 3 print(p.get_current_lead_length()) # > 10 Hints • Don't forget to import Pencil.
Language: Python Function name : findwaldo Parameters : string Returns: int Description: Write a recursive function that takes in a string containing some combination of letters, numbers, and spaces, and return the starting index of the first instance of “waldo” contained in that string. If the string does not contain “waldo”, return -1. This function IS case sensitive, so “waldo” is not the same as “WALDO”. Code using string functions such as .index() and .find() that oversimplify the problem will...
1. a. Function Description: The Python function is "clearSecurity". It receives 2 parameters (databaseScore, obsScore). The first is a float; the second is an integer. The function's purpose is to determine if the person can enter the secure zone. (databasescore-80.5 and obScore-5). The function returns a message saying whether the person is eligible to enter or needs further scrutiny. Fill in the following table. Expected result Function NamePurpose Input (s) and Parameter(s) clearSecurity0 1.b. Write the function code: 1.c. Write...
I need help asap, Python language 2) Write a class to represent a class to represent a Car and its passengers. Write a constructor that takes one additional parameter a number, the total seats in the car. The constructor should save this as a datamember and also initialize an additional datamember, a list, to keep track of the passengers in the car. Write method addRider that takes an additional parameter a string of the passenger to be added to the...
Define a function named how_many_substr_of_string(...) which receives two parameters, the first parameters is a list with strings (name it listst) and the second parameter is a single string (name it st). The function should return a number, indicating how many of the strings in the list listst are substrings in the string st As an example, the following code fragment: listst = ["a","bc","dd"] st = "abc" res = how_many_substr_of_string(listst,st) print (res) should produce the output: 2 Language Python
Function Name: zip_d Parameters: two equal-sized lists Returns: a dictionary Description: Write a function, zip_d, that takes a two equal-sized lists as parameters, and zips each list into a dictionary. Sample Inputs/Outputs: Example Call: zip_d([1,2,3], ['a','b','c']) Expected Return: {1: 'a', 2: 'b', 3: 'c'} Example Call: zip_d([‘a’,’b’,’c’],[9.8,7.6,5.4]) Expected Return: {‘a’:9.8, ’b’:7.6, ’c’:5.4} please answer in python
Python Function Name: unscramble Parameters: a string Returns: a string Description: Write a function, unscramble, that takes an input string, and returns a the unscrambled version of the argument. To unscramble the string: When the string has an odd number of characters, middle character is the first character in the unscrambled result Pairs of remaining characters are added to the result, proceeding left to right from inner-most to outer-most characters. Example Call: unscramble('3cis1') Expected result: ics31 Example Call: unscramble('ocicssol') Expected...
In PYTHON: Write a function that receives a list of integers and returns the number of integers that are larger than the element immediately before them. For example, given [1,2,3,-5,0,-5,-10] the function should return 3 (since 1<2, 2<3, and -5<0).
Language: Python Topic: Dictionaries Function name: catch_flight Parameters: dictionary, tuple containing two strings Returns: dictionary Description: You’ve been stuck in NYC for around 8 months all by yourself because you haven’t been able to find a good time to fly home. You’re willing to go to any city but want to see how many flights to each location fit your budget. You’re given a dictionary that has city names (strings) as the keys and a list of prices (list) and...
Python String Product Function Name: string Multiply Parameters: sentence (str), num (int) Returns: product (int) Description: You're texting your friend when you notice that they replace many letters with numbers. Out of curiosity, you want to find the product of the numbers. Write a function that takes in a string sentence and an int num, and find the product of only the first num numbers in the sentence. If num is 0, return 0. If num > O but there...