What is printed by the following? def grade (score): if score > 90: return ‘A’ elif score > 80: return ‘B’ elif score > 70: return ‘C’ elif score > 60: return ‘D’ else: return ‘F’ print(grade(78))
Blog
Given the following class code that you should assume will c…
Given the following class code that you should assume will correctly execute (ignore any minor syntax errors): class Ticket (object): ticketCount = 0 def __init__ (self, name, event): self.serialNumber = Ticket.ticketCount Ticket.ticketCount += 1 self.cust_name = name self.event = event def __str__ (self): return (‘Tick#’ + str(self.serialNumber) + ‘ – ‘ + self.cust_name + ‘ – ‘ + self.event) def equalTick (self, t_obj): if self == t_obj: return True, ‘dupe ticket’ if not isinstance (t_obj, Ticket): return False, ‘Object not type Ticket’ return (str(self.serialNumber) == str(t_obj.serialNumber) and str(self.event) == str(t_obj.event), ‘comparison done’ )# global code ———————————————-t1 = Ticket (‘K. Ball’, ‘GMU Basketball’)t2 = Ticket (‘Tom Brady’, ‘Pats Game’)t3 = Ticket (‘Gene Shuman’, ‘Nats Game’)t4 = Ticket (‘E. Musk’, ‘SpaceX Launch’)t5 = Ticket (‘K. Ball’, ‘GMU Basketball’)t6 = Ticket (‘A. Trebek’, ‘Jeopardy Audience’)t2.serialNumber = t4.serialNumbert4.event = t2.eventWhat is the display output of t4.equalTick (t2) ?
A hypothetical class called “MyClass” has a method called ‘e…
A hypothetical class called “MyClass” has a method called ‘equals’ with this signature line: def equals (self, in_obj): What code should be added to that method to check whether the input object is the same object as the MyClass object in which the method is being executed?
What can be added to the following code to cause the year to…
What can be added to the following code to cause the year to be displayed when the code is executed? class Date(): def __init__(self, month, day, year, descr = ‘Today’): self.__month = str(month) self.__day = str(day) self.__year = str(year) self.__descr = descr def getYear (self): return self.__year def setYear (self, year): self.__year = year return True # return ‘True’ to indicate success def __str__(self): return(str(self.__month) + ‘/’ + str(self.__day) + ‘/’ + str(self.__year) + ‘ – ‘ + str(self.__descr)) d1 = Date(’10’, ’01’, ‘2023’)d1.setYear(‘2024’)# We want to display the year …
View the following class definition then answer the question…
View the following class definition then answer the question that follows. class Date ( ): def __init__ (self, month, day, year, descr): self.month = month self. day = day self.descr = descr def __str__ (self): return str(self.month) + ‘/’ + str(self.day) + ‘/’ + str(self.year) + ‘ – ‘ + self.descr What statements would be needed to add the capability to the above class to allow a user (a programmer) to test for equality of two different objects? Equality in this case means the day, month, and year match. Check all the statements that would reasonably be included in such an “equals” method that complies with the aforementioned definition of equality.
The program below reads the entire content of the file, assu…
The program below reads the entire content of the file, assuming the file path exists and is correct as specified. fp = open(‘input.txt’, ‘r’) fp.readlines() fp.close()
View the following class definition then answer the question…
View the following class definition then answer the question that follows. class Date ( ): currentYear = 2024 def __init__ (self, month, day, descr): self.month = month self. day = day self.descr = descr def __str__ (self): return str(self.month) + ‘/’ + str(self.day) + ‘/’ + str(self.year) + ‘ – ‘ + self.descr What changes can be done to make the above code function correctly by printing a 2024 date with the Python ‘print’ statement? Check the statements that, each executed by itself (that is, not in combination with another statement), would make the code correctly execute.
What is printed by the following? def receipt (items): …
What is printed by the following? def receipt (items): for n in range(len(items)): print(n, items[n]) ilist = [‘milk’, ‘eggs’, ‘bread’] receipt (ilist)
View the following class definition, then answer the questio…
View the following class definition, then answer the question that follows. class Date ( ): def __init__ (self, month, day, descr): self.month = month self. day = day self.descr = descr def __str__ (self): return str(self.month) + ‘/’ + str(self.day) + ‘/’ + str(self.year) + ‘ – ‘ + self.descr What changes should be done to the above code so that its objects include a year as an attribute? Check all that must be done.
View the following class definition, then answer the questio…
View the following class definition, then answer the question that follows. class Date ( ): def __init__ (self, day, month, year, descr): self.month = month self. day = day self.year = year self.descr = descr def __str__ (self): return str(self.month) + ‘/’ + str(self.day) + ‘/’ + str(self.year) + ‘ – ‘ + self.descrd1 = Date(’01’, ’04’, ‘2025’, ‘Important date’)print(d1) What is the display output of the above code?