Answered step by step
Verified Expert Solution
Question
1 Approved Answer
cs2 final ex. python only please answer quickly Question 1 - 20 Marks Create a class called Sms in this file. Your class must have
cs2 final ex. python only please answer quickly
Question 1 - 20 Marks Create a class called Sms in this file. Your class must have three private instance variables: - A string named 'to_number' - A string name 'content' - An integer named 'sms_count' Create a constructor with a parameter for 'to_number' only. Create a public method named 'send_sms' that takes no arguments and returns a string. This method will be responsible for taking as input the SMS content and sending it to the 'to' number. First, you should validate the 'to_number' variable. If 'to_number' is none or contains nothing, you should return "You must have a valid to number". Then, you should take a line of input from the console and save that into the 'content' instance variable. You must use the input function to do this. If the received content is empty, return "You must enter an SMS body". Next calculate how many SMS messages will be required. A single SMS is 160 characters long, at most. That is, for every 160 characters, an SMS must be sent. Save this result into the 'sms_count' instance variable. Finally, build and return a string of feedback, formatted as follows (in this example, three SMS messages were required): SMS_1 sent to:SMS_2 sent to: SMS_3 sent to: Write appropriate getters and setters. YOUR_NAME YOUR_ID <<<< CHANGE THESE Resources (You can visit this website only. You cannot click links on the webpage): https://docs.python.org/3/library/functions.html#input """ # DEFINE YOUR CLASS HERE # DO NOT MODIFY ANYTHING BELOW if __name__ == '__main__': sms = Sms('0400000000') print(sms.send_sms()) """ Example 1: Enter SMS contents: My SMS SMS_1 sent to 0400000000 """ """ Example 2: Enter SMS contents: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. SMS_1 sent to 0400000000 SMS_2 sent to 0400000000 SMS_3 sent to 0400000000 """ # Should use the properties and setters print(sms.to_number) print(sms.content) print(sms.sms_count) sms.to_number = '0411000000' sms.content = 'New message'
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started