Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

i have to create a code for my assignment . The first parameter represents a puzzle, the second represents a direction ( the value of

i have to create a code for my assignment . The first parameter represents a puzzle, the second represents a direction (the value of one of the constants UP, DOWN, FORWARD and BACKWARD), the third represents the guessed word, the fourth represents the row or column number, and the fifth represents the number of words left to be found before this guess. If this guessed word is found in this puzzle at this location (row or column) and in this direction, return the number of points earned for this guess. Otherwise, return 0. Hint: you will need to call on several helper functions (from above and from the starter code). here are all the function codes that i have made and you need to use them def get_column(puzzle: str, col_num: int)-> str:
"""Return column col_num of puzzle.
Preconditions:
-0<= col_num < number of columns in puzzle
- puzzle is in the proper 'Where's that word?' puzzle format
>>> get_column('abcd
efgh
ijkl
',1)
'bfj'
>>> get_column('abcd
efgh
ijkl
',0)
'aei'
"""
puzzle_list = puzzle.strip().split('
')
column =''
for row in puzzle_list:
column = column + row[col_num]
return column
def get_row_length(puzzle: str)-> int:
"""Return the length of a row in puzzle.
Preconditions:
- puzzle is in the proper 'Where's that word?' puzzle format
>>> get_row_length('abcd
efgh
ijkl
')
4
>>> get_row_length('ab
cd
ef
')
2
"""
return len(puzzle.split('
')[0])
def string_contains(text1: str, text2: str)-> bool:
"""Return True if and only if text2 appears anywhere in text1.
>>> string_contains('abc','bc')
True
>>> string_contains('abc','cb')
False
"""
return text2 in text1
# Implement the required functions below.
#
# We have provided the complete docstring (but not the body!) for the first
# function you are to write. Write a function body for the function
# get_current_player and then follow the Function Design Recipe to produce
# complete functions for get_winner, get_factor, reverse, get_row, get_points
# and check_guess. When you have completed all of these functions, run the
# file puzzle_program.py to play the game!
def get_current_player(player_one_turn: bool)-> str:
"""Return 'player one' if and only if player_one_turn is True; otherwise,
return 'player two'.
>>> get_current_player(True)
'player one'
>>> get_current_player(False)
'player two'
"""
if player_one_turn == True:
return P1
else:
return P2
#YOU MIGHT BE ABLE TO SIMPLIFY THE BODY DESCRIPTION MORE AND THE RETURN
#STATEMENT
def get_winner(score_of_player_one: int, score_of_player_two: int)-> str:
""" Return P1_WINS if score_of_player_one is greater than score_of_player_two, P2_WINS if score_of_player_two > score_of_player_one; otherwise, return TIE
>>> get_winner (16,9)
P1_WINS
>>> get_winner (7,12)
P2_WINS
>>> get_winner (8,8)
TIE
"""
if score_of_player_one > score_of_player_two:
return P1_WINS
elif score_of_player_two > score_of_player_one:
return P2_WINS
else:
return TIE
def get_factor(direction: str)-> int:
"""
>>> get_factor('FORWARD')
1
>>> get_factor('BACKWORD')
3
>>> get_factor('UP')
4
>>> get_factor('DOWN')
2
"""
if direction == 'FORWARD':
return FORWARD_FACTOR #1
elif direction == 'BACKWORD':
return BACKWARD_FACTOR #3
elif direction =='UP':
return UP_FACTOR #4
else:
return DOWN_FACTOR #2
def reverse(input_string:str)-> str:
"""Return a reversed copy of the input_string
>>> reverse('anya')
'ayna'
>>> reverse('kaveh')
'hevak'
>>> reverse('jacqueline')
'einleuqcaj'
"""
if not input_string:
return ""
return input_string[-1]+ reverse(input_string[:-1])
def get_row(puzzle:str, row_num:int)-> str:
"""Return the letters in the corresponding row_num. The letters must be
in the same order as they appear in the puzzle. The first row is row_num 0.
>>> get_row('abcd
efgh
ijkl
',1)
'efgh'
>>>get_row('abcd
efgh
ijkl
',-1)
'ijkl'
"""
#call on starter function get_row_length
row_length = get_row_length(puzzle)
start_index = row_num *( row_length +1)
end_index = start_index + row_length
return puzzle[start_index:end_index]
def get_points(direction:str, words_remaining:int)-> int:
"""Return the number of points earned when the word is found in the
correct direction based on the words_remaining.
>>> get_points('FORWARD',4)
18
>>> get_points('BACKWARD',3)
26
>>> get_points('UP',8)
20
>>> get_points('DOWN',-3)
38

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Students also viewed these Databases questions

Question

Brief the importance of span of control and its concepts.

Answered: 1 week ago

Question

What is meant by decentralisation?

Answered: 1 week ago

Question

Write down the Limitation of Beer - Lamberts law?

Answered: 1 week ago