Complete the validate_index(coins_list, position_number) function. This function takes the coins list and the position o

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Complete the validate_index(coins_list, position_number) function. This function takes the coins list and the position o

Post by answerhappygod »

Complete The Validate Index Coins List Position Number Function This Function Takes The Coins List And The Position O 1
Complete The Validate Index Coins List Position Number Function This Function Takes The Coins List And The Position O 1 (33.61 KiB) Viewed 70 times
Complete the validate_index(coins_list, position_number) function. This function takes the coins list and the position of the "$" symbol to be moved as parameters. The function returns True if the position is in the range of 1 to 9 (inclusive) and the element specified by the given position in the parameter list is "$", and returns False otherwise. Note: The position number is a number starting from 1, therefore moving the "$" symbol in position 9 is referring to the "$" symbol at index 8 of the parameter coins list. For example: Test Result data = ['-', 's', 'a', 'a', 's', print(validate_index(data, 2)) print(validate_index(data, 3)) print(validate_index(data, -1)) print(validate_index (data, 10)) print(validate_index(data, o)) '$', 's', '-'] True False False False False data = ['-', '$', '-', '-', 'S', '-', 's', 's', '-'] False print(validate_index(data, 3)) False print(validate_index(data, 4)) Answer: (penalty regime: 0%) Reset answer 1 2

Complete the validate_move (coins_list, position_number, to_move) function. This function takes the coins list, the position of the "$" symbol to be moved and the number of positions to move as parameters. The function returns True if the number of places to move is a valid number, i.e. the coin will always end up in an empty location and will never land on or pass another coin, and returns False otherwise. For example, consider the following code fragment: data = ['-', 's', '-', '-', 's', '-', 's', 's', '-'] print(validate_move(data, 5, 2)) print(validate_move (data, 7, 3)) The second statement checks if the element at index 3 and index 2 are not equal to '$'. The third statement checks if the element at index 5, index 4 and index 3 are not equal to 'S'. Note: you can assume that the element at the given index (1.e. position number - 1) is equal to "$". For example: Test Result data = ['-', 's', '', 'a', 'S', '-', 'S', 'S', '-'] True print(validate_move(data, 5, 2)) False print(validate_move(data, 3, 1)) False print(validate_move(data, 2, 5)) False print(validate_move (data, 5, 3)) data = ['-', 'S', '-', '-', '$', '-', 's', 's', '-'] True print(validate_move (data, 2, 1)) True print(validate_move(data, 7, 1))

Complete the move_dollar_to_the_left(coins_list, position_number, to_move) function. This function takes three parameters (the coins list, the position of the "$" symbol to be moved and the number of positions to move). Firstly, work out the new position for the "$" symbol being moved (always moving to the left). The function replaces the "$" symbol in the position given by the parameter, position_number, with a "-" symbol, and moves a "$" symbol into the new position in the list. For example, if the coins list is ['$', '-', '$' -', '-' '$'] and the position number to move the coin from is 9 (the last position in the list) and the number of places to move is 3, the function should modify the list to: "['$', '-' ', '$', '$', '$', '-', '-', '-']. Note: L' • The position number is a number starting from 1, therefore referring to the "$" symbol in position 9 is referring to the "$" symbol at index 8 of the parameter list. • The function makes changes in place. (i.e. it changes the list that is passed to the function. It does not create a new list and it does not return anything). For example: Test Result '$ '$', '-'] data = ['-', 'S', '-', '-', 's', '-', 's', 's', '-'] ['$', '', move_dollar_to_the_left(data, 2, 1) print(data) '-', '-', 's', 's', '-'] data = ['-', '$', '-', '-', '$', '-', 'S', 'S', '-'] ['-', 's', 's', '-', move_dollar_to_the_left(data, 5, 2) print(data) Answer nenalty regime: 4
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply