Create a module and name it Lastname_Firstname_hw1.py. In the module, add the following functions: 1. Write...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Create a module and name it Lastname_Firstname_hw1.py. In the module, add the following functions: 1. Write a function named problem1 that accepts a list of integers as the argument. Then your function should remove all the odd numbers from the list and sort the remaining non-odd numbers in descending order. Return the list. Call the function and display the return result. Test your function with the test case: if the input list is [1, 6, 4, 3, 7, 2, 5], then your function should return [6, 4, 2] (10 pts) 2. Write a function named problem2 that accepts a string. Assume the string contains a lot of numbers that are separated by commas. Remove all the duplicates from the list, then calculate and return the sum of remaining elements. Call the function and display the return result. Test your function with this test case: if input string is "1,2,3,3,4,4,5", then your method should return 15. (10 pts) 3. Write a function named problem3 that prompts the user for a sequence of integers and appends them to a list. Each integer can appear only once in the list. You need to ask the user to re-enter a different integer if the entered integer already exists in the list. Calculate and return the sum of the list. Call the function and display the return result. You may test it with the test case: if input sequence 1, 2,3, 4, 5, then your function should return 15. (10 pts) 4. Write a function named problem4 that accepts a string as the argument. Find and return the most frequent digit. You cannot use the collections module to solve this problem. Call the function with the test case and display the return result. Test case: if the given string is 'abc123 cda 345cc3456', your function should return 3 (only digits are considered). (10 pts) Acti Go to 5. Write a function named problem5 that accepts a string and a positive integer k. Find and return a list with any k distinct characters. If k is greater than the length of the given string, return all the distinct characters. You cannot use the collections module to solve this problem. Call the function with the test case and display the return result. Test case: if the given string is 'aaabbbcccdddeeefffggg' and k = 5, your function should return any five distinct characters, e.g., ['a', 'b', 'c', 'd', 'e']. (10 pts) 6. Write a function named problem6 that accepts a string and a tag as the arguments. Assume this string contains a sequence of words that are separated by spaces. Add the tag around each word. Call the function with the test case and display the return result. Test case: if the given string is 'hello world python break' and the tag is '#', your function should return '#hello# #world# #python# #break#'. (10 pts) 7. Write a function named problem7 to merge two strings. This function should accept two strings as the arguments. Assume both strings contain lower case letters only. Merge the two strings and order the letters alphabetically, then return the result. Call the function with the test case and display the result. Test case: if the two strings are 'dagc' and 'fbhe', your function should return 'abcdefgh'. (10 pts) 8. Create a class named Student. The Student class should have a static variable, numStudent, and five instance variables. (30 pts) Write the following variables: Static variable Instance variables name: the student's full name, string, e.g., "John Doe", must be specified when instantiated. id: the student's id, string, created based on num_student, e.g., the first student object's id should be "1", the second student object's id should be "2". major: the student's major, string, its default value is "Undeclared", can also be specified when instantiated. gpa: the student's current gpa, float, initial value = 0.0. username: string, each student is assigned an automatically generated username following the rules below: Get the first letter of the student's first name. Get the first five letters of the student's last name. If student's last name is less than the required number of letters in length, then use the entire name. Get the student's id. I ■ num_student: the number of the student objects that have been created, static, int, initial value = 0. I I ■ Concatenate the three sets of letters then convert to lower case to generate the login name. Write a method called create_password() to create the password for the student. password: string, the default password is "ABC123abc!", each student can create their own password by following the rules below: A password must ■ Be at least 8 characters long. I Contain at least one uppercase letter and at least one lower case letter. ■ Contain at least one number. Contain at least one special symbol: ! @ # % &. Write a static method called verify_password(password) to verify if the given password is valid. Return True if yes, return False otherwise. The user must re-enter a different password if the specified password is not valid. Write the additional methods: ■ get_name() get_id() get_major() get_gpa() I get_username() Page 2 of 3 ■ first. Implement the following special methods so that student objects should be able to be compared by their gpa. I I I get_password() set_name(name): update a student's name set_major(major): update a student's major set_password(password): update a student's password. The new password needs to be verified I _It____(self, other) _le__(self, other) _eq___(self, other) _ne___(self, other) _ge_(self, other) _gt__(self, other) To get called on comparison using < operator. To get called on comparison using <= operator. To get called on comparison using: = = operator. To get called on comparison using != operator. To get called on comparison using >= operator. To get called on comparison using > operator. Test cases: student1 = Student ("John Doe", "Computer Science", "Password1%") ## id is 1, username is jdoe1, password is Password1% student2 = Student("Emily Johnson", "Cybersecurity") ## id is 2, username is ejohns2, password is "ABC123abc!" print(student1 student2, student1 > student2, student1 <= student2) Create a class named HonorStudent. An honor student is a student (created in problem8) who has an additional attribute: minors: the student's minors, a list of string, an honor student can have up to three minors. Write an add minor(minor) method to add the given minor to this honor student. Raise the exception IndexError "This honor student already has three minors" if the student wants to add the fourth minor. Test case: student3 = HonorStudent("Michael Watson", "Computer Science", "#passWORD111#") Then add "Biology", "Psychology", "Business" and "Mathematics" as minors. Page 3 of 3 Create a module and name it Lastname_Firstname_hw1.py. In the module, add the following functions: 1. Write a function named problem1 that accepts a list of integers as the argument. Then your function should remove all the odd numbers from the list and sort the remaining non-odd numbers in descending order. Return the list. Call the function and display the return result. Test your function with the test case: if the input list is [1, 6, 4, 3, 7, 2, 5], then your function should return [6, 4, 2] (10 pts) 2. Write a function named problem2 that accepts a string. Assume the string contains a lot of numbers that are separated by commas. Remove all the duplicates from the list, then calculate and return the sum of remaining elements. Call the function and display the return result. Test your function with this test case: if input string is "1,2,3,3,4,4,5", then your method should return 15. (10 pts) 3. Write a function named problem3 that prompts the user for a sequence of integers and appends them to a list. Each integer can appear only once in the list. You need to ask the user to re-enter a different integer if the entered integer already exists in the list. Calculate and return the sum of the list. Call the function and display the return result. You may test it with the test case: if input sequence 1, 2,3, 4, 5, then your function should return 15. (10 pts) 4. Write a function named problem4 that accepts a string as the argument. Find and return the most frequent digit. You cannot use the collections module to solve this problem. Call the function with the test case and display the return result. Test case: if the given string is 'abc123 cda 345cc3456', your function should return 3 (only digits are considered). (10 pts) Acti Go to 5. Write a function named problem5 that accepts a string and a positive integer k. Find and return a list with any k distinct characters. If k is greater than the length of the given string, return all the distinct characters. You cannot use the collections module to solve this problem. Call the function with the test case and display the return result. Test case: if the given string is 'aaabbbcccdddeeefffggg' and k = 5, your function should return any five distinct characters, e.g., ['a', 'b', 'c', 'd', 'e']. (10 pts) 6. Write a function named problem6 that accepts a string and a tag as the arguments. Assume this string contains a sequence of words that are separated by spaces. Add the tag around each word. Call the function with the test case and display the return result. Test case: if the given string is 'hello world python break' and the tag is '#', your function should return '#hello# #world# #python# #break#'. (10 pts) 7. Write a function named problem7 to merge two strings. This function should accept two strings as the arguments. Assume both strings contain lower case letters only. Merge the two strings and order the letters alphabetically, then return the result. Call the function with the test case and display the result. Test case: if the two strings are 'dagc' and 'fbhe', your function should return 'abcdefgh'. (10 pts) 8. Create a class named Student. The Student class should have a static variable, numStudent, and five instance variables. (30 pts) Write the following variables: Static variable Instance variables name: the student's full name, string, e.g., "John Doe", must be specified when instantiated. id: the student's id, string, created based on num_student, e.g., the first student object's id should be "1", the second student object's id should be "2". major: the student's major, string, its default value is "Undeclared", can also be specified when instantiated. gpa: the student's current gpa, float, initial value = 0.0. username: string, each student is assigned an automatically generated username following the rules below: Get the first letter of the student's first name. Get the first five letters of the student's last name. If student's last name is less than the required number of letters in length, then use the entire name. Get the student's id. I ■ num_student: the number of the student objects that have been created, static, int, initial value = 0. I I ■ Concatenate the three sets of letters then convert to lower case to generate the login name. Write a method called create_password() to create the password for the student. password: string, the default password is "ABC123abc!", each student can create their own password by following the rules below: A password must ■ Be at least 8 characters long. I Contain at least one uppercase letter and at least one lower case letter. ■ Contain at least one number. Contain at least one special symbol: ! @ # % &. Write a static method called verify_password(password) to verify if the given password is valid. Return True if yes, return False otherwise. The user must re-enter a different password if the specified password is not valid. Write the additional methods: ■ get_name() get_id() get_major() get_gpa() I get_username() Page 2 of 3 ■ first. Implement the following special methods so that student objects should be able to be compared by their gpa. I I I get_password() set_name(name): update a student's name set_major(major): update a student's major set_password(password): update a student's password. The new password needs to be verified I _It____(self, other) _le__(self, other) _eq___(self, other) _ne___(self, other) _ge_(self, other) _gt__(self, other) To get called on comparison using < operator. To get called on comparison using <= operator. To get called on comparison using: = = operator. To get called on comparison using != operator. To get called on comparison using >= operator. To get called on comparison using > operator. Test cases: student1 = Student ("John Doe", "Computer Science", "Password1%") ## id is 1, username is jdoe1, password is Password1% student2 = Student("Emily Johnson", "Cybersecurity") ## id is 2, username is ejohns2, password is "ABC123abc!" print(student1 student2, student1 > student2, student1 <= student2) Create a class named HonorStudent. An honor student is a student (created in problem8) who has an additional attribute: minors: the student's minors, a list of string, an honor student can have up to three minors. Write an add minor(minor) method to add the given minor to this honor student. Raise the exception IndexError "This honor student already has three minors" if the student wants to add the fourth minor. Test case: student3 = HonorStudent("Michael Watson", "Computer Science", "#passWORD111#") Then add "Biology", "Psychology", "Business" and "Mathematics" as minors. Page 3 of 3
Expert Answer:
Answer rating: 100% (QA)
It looks like you want to create a Python module with specific functions Here is an example of how y... View the full answer
Related Book For
Concepts of Database Management
ISBN: 978-111182591
7th edition
Authors: Philip J. Pratt, Joseph J. Adamski
Posted Date:
Students also viewed these programming questions
-
Can you think of the conditions in which democratic leadership would thrive? Try to imagine a workplace environment. What would be some characteristics of an environment that would appreciate and...
-
EXAM Questions 1. a) How much memory in Mbytes can be accessed using 10 bits for addressing assuming 8 bits (or 1 byte) capacity for each memory location. (5points)
-
You are required to write a Python program that will manage character (heroes and villain) information. Character (hero and villain) information will be stored in a text file that will be read in...
-
After reviewing the definition of Behavior Leadership Theory, explain what effect behavioral leadership theory has on traditional police in their role as a chief or any other leadership role in law...
-
Why are external memory managers not able to replace the internal page-replacement algorithms? What information would need to be made available to the external managers for the latter to make...
-
"Manitowoc Crane (U.S.) exports heavy crane equipment to several Chinese dock facilities. Sales are currently 10,000 units per year at the yuan equivalent of $24,000 each. The Chinese yuan (renminbi)...
-
In an engine working on the diesel cycle, the air-fuel by weight is 50:1. The temperature of air at the beginning of combustion is 40C and the compression ratio is 15. What is the ideal efficiency of...
-
Steven Corporation has been authorized to issue 40,000 shares of $100 par value, 8%, noncumulative preferred stock and 2,000,000 shares of no-par common stock . The corporation assigned a $5 stated...
-
1. Write a paragraph about the "Fermi Paradox". 2. Define the Megawatt, Gigawatt and Terawatt units of power. Access the internet to determine the latest available figure of total global power...
-
The lifetime (in months) of a battery is modeled by a random variable X that has pdf f ( x ) = K x 1 ( x > 0 ) where K = ln ( 1 / ) for an unknown parameter ( 0 , 1 ) . (Here 1 ( x > 0 )...
-
Bob is a business consultant and plans to expand his business to include his two adult children, Tracy and Cody. Bob, Tracy, and Cody file jointly with their spouses and all in the 24 percent...
-
Open demo.savin SPSS. using two variables: CAPPUN and GUNLAW. Because CAPPUN is coded backwards (1=not liberal, 2=liberal) compared to GUNLAW (1=liberal, 2=not liberal), you will need to begin this...
-
Let Z (Z,..., Zp) form a random vector where each variable has a N(0, 1) dis- tribution. Let be a positive definite symmetric square matrix and = TT be the Cholesky decomposition of where T is an...
-
At the time of acquisition, December 31, 2021, SSI had common shares of $200,000 and retained earnings of $704,000. The fair value of each of SSI's identifiable net assets at time of acquisition is...
-
PROBLEM 1 Class Workshop Exercise: Consider a person strengthening the shoulder muscles by means of dumbbell exercises. The figure bellow illustrates the position of the left arm when the arm is...
-
Pharmacy Consulting is a privately held regional provider based in Ohio, with revenues of $25 million annually, and whose services include pharmacy, nursing and dietary nutrition care. Key client...
-
9. Problem 3.4.18. If A = QR, find a simple formula for the projection matrix P onto the column space of A.
-
On October 31 Juanita Ortega, owner of Outback Guide Service, received a bank statement dated October 30. Juanita found the following: 1. The checkbook has a balance of $2,551.34. 2. The bank...
-
When does a DBA use forward recovery? What are the forward recovery steps?
-
What is deadlock? How does it occur?
-
1. Design a database for Ray. He is interested in movie DVDs and wants to keep information on movies, actors, and directors in a database. The only user is Ray, and he needs to produce the following...
-
(a) During a certain day the outdoor temperature ranges between \(60^{\circ} \mathrm{F}\) and \(80^{\circ} \mathrm{F}\). What is the corresponding range in degrees Celsius and in kelvins? (b) The...
-
Which is greater in each pair: (a) the thermal energy of a pool of water or that of a glass of water at the same temperature, (b) the heat capacity of a pool of water or that of a glass of water at...
-
Which of the following systems undergo a quasistatic process? (a) A gas-containing balloon is popped inside a vacuum container. System: container, gas, and balloon. (b) A cup of coffee cools down....
Study smarter with the SolutionInn App