Need help with your Discussion

Get a timely done, PLAGIARISM-FREE paper
from our highly-qualified writers!

glass
pen
clip
papers
heaphones

SIT Python Alphanumeric Characters Questions

SIT Python Alphanumeric Characters Questions

SIT Python Alphanumeric Characters Questions

Description

   

Unformatted Attachment Preview

You should edit the file “answer.py” and answer the questions asked.
Please don’t try to rename the files. Please don’t try to edit other files.
Make sure your code is bugs free and ready to run.
Complete the code
answer.py
“””
QUESTION 1:
============================================================
============================================
Give a list of numbers, write a function to find the maximum number in the list.
Note: For the purpose of this problem, we define empty list will return None.
NOTE: DO NOT USE “MAX” KEYWORD. WRITE algorithm using loop.
Example 1:
========================================
Input: [10, 5, 20, 15, 25]
Output: 25
Example 2:
========================================
Input:[10,10,10]
Output: 10
Example 3:
========================================
Input: []
Output: None
“””
def find_maximum(numbers):
“””
QUESTION 2:
============================================================
============================================
Given n pairs of parentheses, write a function to generate all combinations of
well-formed parentheses.
Write a function named generateParenthesis that takes an integer as an input
and returns a list of strings
as an output. Note that you can define a function inside a function if necessary.
Example 1:
========================================
Input: 0
Output: [”]
Example 2:
========================================
Input: 1
Output: [‘()’]
Example 3:
========================================
Input: 2
Output: [‘(())’, ‘()()’]
Example 4:
========================================
Input: 3
Output: [‘((()))’, ‘(()())’, ‘(())()’, ‘()(())’, ‘()()()’])
“””
def generateParenthesis(n):
“””
QUESTION 3:
============================================================
============================================
Given a string, determine if it is a palindrome, considering only alphanumeric
characters and ignoring cases.
Note: For the purpose of this problem, we define empty string as valid
palindrome.
Example 1:
========================================
Input: “A man, a plan, a canal: Panama”
Output: true
Explanation:
After removing non-alphanumeric charactors and ignoring cases, the input is:
amanaplanacanalPanama
which reads the same as backward and forward, so it is true.
Example 2:
=========================================
Input: “race a car”
Output: false
Write a function named isPalindrome that takes a string as an input and returns
a bool as an output.
Explanation:
After removing non-alphanumeric charactors and ignoring cases, the input is:
raceacar
which does not read the same as backward and forward, so it is false.
“””
ddef isPalindrome(x):
To test the code in
answer_test.py
import pytest
import answer
class TestAnswer():
__correct__ = 0
__total__ = 0
@classmethod
def setup_class(cls):
print(“Before”)
cls.__correct__ = 0
cls.__total__ = 0
@classmethod
def teardown_class(cls):
print(f”Score:{(cls.__correct__/cls._
_total__)*100}%”)
def test_Q1_normal_list(self):
TestAnswer.__total__ += 1
test_list = [10, 5, 20, 15, 25]
output =
answer.find_maximum(test_list)
assert(output == 25)
TestAnswer.__correct__ += 1
def
test_Q1_same_number_list(self):
TestAnswer.__total__ += 1
test_list = [10, 10, 10, 10]
output =
answer.find_maximum(test_list)
assert(output == 10)
TestAnswer.__correct__ += 1
def test_Q1_empty_list(self):
TestAnswer.__total__ += 1
test_list = []
output =
answer.find_maximum(test_list)
assert(output == None)
TestAnswer.__correct__ += 1
def test_Q2_Input_0(self):
TestAnswer.__total__ += 1
test_num = 0
output =
answer.generateParenthesis(test_n
um)
assert(output == [”])
TestAnswer.__correct__ += 1
def test_Q2_Input_1(self):
TestAnswer.__total__ += 1
test_num = 1
output =
answer.generateParenthesis(test_n
um)
assert(output == [‘()’])
TestAnswer.__correct__ += 1
def test_Q2_Input_2(self):
TestAnswer.__total__ += 1
test_num = 2
output =
answer.generateParenthesis(test_n
um)
assert(output == [‘(())’, ‘()()’])
TestAnswer.__correct__ += 1
def test_Q2_Input_3(self):
TestAnswer.__total__ += 1
test_num = 3
output =
answer.generateParenthesis(test_n
um)
assert(output == [‘((()))’, ‘(()())’, ‘(())()’,
‘()(())’, ‘()()()’])
TestAnswer.__correct__ += 1
def test_Q2_Input_4(self):
TestAnswer.__total__ += 1
test_num = 4
output =
answer.generateParenthesis(test_n
um)
assert(output ==
[‘(((())))’,'((()()))’,'((())())’,'((()))()’,'(()(()))’,'((
)()())’,
‘(()())()’,'(())(())’,'(())()()’,'()((()))’,'()(()())’,'()(
())()’,'()()(())’,'()()()()’])
TestAnswer.__correct__ += 1
def test_Q2_Input_3(self):
TestAnswer.__total__ += 1
test_num = 3
output =
answer.generateParenthesis(test_n
um)
assert(output == [‘((()))’, ‘(()())’, ‘(())()’,
‘()(())’, ‘()()()’])
TestAnswer.__correct__ += 1
def test_Q3_normal_list(self):
TestAnswer.__total__ += 1
test_str= “A man, a plan, a canal:
Panama”
output =
answer.isPalindrome(test_str)
assert(output == True)
TestAnswer.__correct__ += 1
def test_Q3_normal_list_2(self):
TestAnswer.__total__ += 1
test_str= “Was it a car or a cat I
saw?”
output =
answer.isPalindrome(test_str)
assert(output == True)
TestAnswer.__correct__ += 1
def test_Q3_empty_list(self):
TestAnswer.__total__ += 1
test_str= “”
output =
answer.isPalindrome(test_str)
assert(output == True)
TestAnswer.__correct__ += 1
def test_Q3_wrong_list(self):
TestAnswer.__total__ += 1
test_str= “hello”
output =
answer.isPalindrome(test_str)
assert(output == False)
TestAnswer.__correct__ += 1
def test_Q3_wrong_list_2(self):
TestAnswer.__total__ += 1
test_str= “race a car”
output =
answer.isPalindrome(test_str)
assert(output == False)
TestAnswer.__correct__ += 1
def test_Q3_str_num_true(self):
TestAnswer.__total__ += 1
test_str= “1234321”
output =
answer.isPalindrome(test_str)
assert(output == True)
TestAnswer.__correct__ += 1
def test_Q3_str_num_wrong(self):
TestAnswer.__total__ += 1
test_str= “1234321a”
output =
answer.isPalindrome(test_str)
assert(output == False)
TestAnswer.__correct__ += 1

Purchase answer to see full
attachment
Explanation & Answer:

3 Questions
User generated content is uploaded by users for the purposes of learning and should be used following Studypool’s honor code & terms of service.

Have a similar assignment? "Place an order for your assignment and have exceptional work written by our team of experts, guaranteeing you A results."

Order Solution Now

Our Service Charter


1. Professional & Expert Writers: Essay Noon only hires the best. Our writers are specially selected and recruited, after which they undergo further training to perfect their skills for specialization purposes. Moreover, our writers are holders of masters and Ph.D. degrees. They have impressive academic records, besides being native English speakers.

2. Top Quality Papers: Our customers are always guaranteed of papers that exceed their expectations. All our writers have +5 years of experience. This implies that all papers are written by individuals who are experts in their fields. In addition, the quality team reviews all the papers before sending them to the customers.

3. Plagiarism-Free Papers: All papers provided by Essay Noon are written from scratch. Appropriate referencing and citation of key information are followed. Plagiarism checkers are used by the Quality assurance team and our editors just to double-check that there are no instances of plagiarism.

4. Timely Delivery: Time wasted is equivalent to a failed dedication and commitment. Essay Noon are known for the timely delivery of any pending customer orders. Customers are well informed of the progress of their papers to ensure they keep track of what the writer is providing before the final draft is sent for grading.

5. Affordable Prices: Our prices are fairly structured to fit in all groups. Any customer willing to place their assignments with us can do so at very affordable prices. In addition, our customers enjoy regular discounts and bonuses.

6. 24/7 Customer Support: At Essay Noon, we have put in place a team of experts who answer all customer inquiries promptly. The best part is the ever-availability of the team. Customers can make inquiries anytime.

We Can Write It for You! Enjoy 20% OFF on This Order. Use Code SAVE20

Stuck with your Assignment?

Enjoy 20% OFF Today
Use code SAVE20