×
Reviews 4.9/5 Order Now

Program To Work with String Manipulation Questions in Python Assignment Solution

July 05, 2024
Dr. Muhammad Rahman
Dr. Muhammad
🇸🇬 Singapore
Python
Dr. Muhammad Rahman holds a Ph.D. in Computer Engineering and has successfully completed over 900 Python programming test assignments with ProgrammingHomeworkHelp.com. His expertise lies in Python for cybersecurity, network programming, data encryption, and software development.
Key Topics
  • Instructions
  • Requirements and Specifications
Tip of the day
Use virtual environments to manage dependencies and avoid version conflicts. Test functions with edge cases and leverage tools like pytest to automate checks—most Python bugs arise from unnoticed input variations rather than syntax issues.
News
Modern ecosystems built around libraries like TensorFlow and PyTorch continue to dominate coursework, as universities emphasize AI, data science, and real-world application development—driving demand for expert programming assignment support.

Instructions

Objective

Write a python assignment program to work with string manipulation questions.

Requirements and Specifications

Program to work with string manipulation questions in python

Program to work with string manipulation questions in python 1

Program to work with string manipulation questions in python 2

Program to work with string manipulation questions in python 3

Program to work with string manipulation questions in python 4

Source Code

QUESTION 1 def up_down_strings(los): alpha = 'abcdefghijklomnpqrstuvwxyz' for j in range(len(los)-1, -1, -1): s = los[j] prev = alpha.index(s[0]) - alpha.index(s[1]) is_ok = True for i in range(1, len(s)-1): curr = alpha.index(s[i]) - alpha.index(s[i+1]) if prev * curr >= 0: is_ok = False break prev = curr if not is_ok: del los[j] if __name__ == '__main__': test = ['yygrees', 'itsy', 'garbs', 'beets', 'abc', 'sole'] up_down_strings(test) print(test) QUESTION 2 def othello(board, turn, row, col): if board[row][col] != '': return False rows = len(board) cols = len(board[0]) # down step = 0 while True: step += 1 if row + step >= rows: break if board[row+step][col] == '': break if board[row+step][col] == turn: if step >= 2: return True else: break # up step = 0 while True: step += 1 if row - step < 0: break if board[row - step][col] == '': break if board[row - step][col] == turn: if step >= 2: return True else: break # right step = 0 while True: step += 1 if col + step >= rows: break if board[row][col+step] == '': break if board[row][col+step] == turn: if step >= 2: return True else: break # left step = 0 while True: step += 1 if col - step < 0: break if board[row][col - step] == '': break if board[row][col - step] == turn: if step >= 2: return True else: break # right-down step = 0 while True: step += 1 if row + step >= rows: break if col + step >= cols: break if board[row+step][col+step] == '': break if board[row+step][col+step] == turn: if step >= 2: return True else: break # left-down step = 0 while True: step += 1 if row + step >= rows: break if col - step < 0: break if board[row + step][col-step] == '': break if board[row + step][col-step] == turn: if step >= 2: return True else: break # right-up step = 0 while True: step += 1 if row - step < 0: break if col + step >= cols: break if board[row-step][col+step] == '': break if board[row-step][col+step] == turn: if step >= 2: return True else: break # left-up step = 0 while True: step += 1 if row - step < 0: break if col - step < 0: break if board[row - step][col-step] == '': break if board[row - step][col-step] == turn: if step >= 2: return True else: break return False if __name__ == '__main__': board = [[ '', '', '', '', '', '', '', ''], [ '', '', '', '', '', '', '', ''], [ '', '', 'B', 'B', 'B', '', '', ''], [ '', 'W', 'B', 'W', 'W', '', 'B', ''], [ '', 'W', 'B', 'W', 'W', 'W', 'W', ''], [ '', '', 'W', 'W', 'W', '', '', ''], [ '', '', '', 'W', '', '', '', ''], [ '', '', '', '', '', '', '', '']] print(othello(board, 'B', 3, 0)) print(othello(board, 'W', 3, 0)) board2 = [['B', 'W', 'B', 'B', 'B', 'W', 'B', 'B'], ['W', 'B', 'B', 'W', 'W', 'B', 'B', 'B'], ['B', 'B', 'W', 'W', 'B', 'B', 'B', 'B'], ['B', 'W', 'W', 'W', 'W', 'W', 'W', 'W'], ['W', 'W', 'W', 'W', 'W', 'W', 'B', 'B'], ['B', 'B', 'W', 'W', 'W', 'B', 'B', 'W'], ['B', 'B', 'W', 'B', 'B', 'B', 'W', 'W'], ['B', 'B', 'W', 'B', 'B', 'B', 'W', 'W']] print(othello(board2, 'W', 1, 2)) QUESTION 3 def multiply_polynomials(poly1, poly2): m = max(len(poly1), len(poly2)) n = len(poly1) + len(poly2) - 1 result = [] for i in range(n): result.append(0) for i in range(len(poly1)): for j in range(len(poly2)): result[i+j] += poly1[i] * poly2[j] return result if __name__ == '__main__': P1 = [151493] P2 = [215578] print(multiply_polynomials(P1, P2)) P1 = [1, 2, 3] P2 = [4 ,5] print(multiply_polynomials(P1, P2))

Similar Samples

Explore our sample solutions to get a glimpse of our expertise at programminghomeworkhelp.com. Our comprehensive, well-documented code examples showcase our ability to tackle diverse programming challenges across various languages and platforms. Trust our proficiency to help you excel in your programming courses.