'''simple docstring'''




import builtins
import sys

from ...utils.imports import _is_package_available
from . import cursor, input
from .helpers import Direction, clear_line, forceWrite, linebreak, move_cursor, reset_cursor, writeColor
from .keymap import KEYMAP


__UpperCAmelCase     							=False
try:
  __UpperCAmelCase     							=_is_package_available("google.colab")
except ModuleNotFoundError:
  pass




@input.register
class     a__      :






     def __init__( self		:		Dict  ,				a		:		str = None  ,				a		:		list = []    ):





         """simple docstring"""



         __lowerCamelCase		=  0
         __lowerCamelCase		=  choices
         __lowerCamelCase		=  prompt
         if sys.platform == "win32":
             __lowerCamelCase		=  '''*'''
         else:
             __lowerCamelCase		=  '''➔ '''






     def    SCREAMING_SNAKE_CASE__   ( self		:		str  ,				a		:		int  ,				a		:		str = ""    ):





         """simple docstring"""



         if sys.platform != "win32":
             writeColor(self.choices[index]  ,				32  ,				a    )
         else:
             forceWrite(self.choices[index]  ,				a    )






     def    SCREAMING_SNAKE_CASE__   ( self		:		List[Any]  ,				a		:		int    ):





         """simple docstring"""



         if index == self.position:
             forceWrite(f""" {self.arrow_char} """    )
             self.write_choice(a    )
         else:
             forceWrite(f"""    {self.choices[index]}"""    )
         reset_cursor()






     def    SCREAMING_SNAKE_CASE__   ( self		:		Any  ,				a		:		Direction  ,				a		:		int = 1    ):





         """simple docstring"""



         __lowerCamelCase		=  self.position
         if direction == Direction.DOWN:
             if self.position + 1 >= len(self.choices    ):
                 return
             self.position += num_spaces
         else:
             if self.position - 1 < 0:
                 return
             self.position -= num_spaces
         clear_line()
         self.print_choice(a    )
         move_cursor(a  ,				direction.name    )
         self.print_choice(self.position    )






     @input.mark(KEYMAP['''up''']    )
     def    SCREAMING_SNAKE_CASE__   ( self		:		Union[str, Any]    ):





         """simple docstring"""



         self.move_direction(Direction.UP    )






     @input.mark(KEYMAP['''down''']    )
     def    SCREAMING_SNAKE_CASE__   ( self		:		Union[str, Any]    ):





         """simple docstring"""



         self.move_direction(Direction.DOWN    )






     @input.mark(KEYMAP['''newline''']    )
     def    SCREAMING_SNAKE_CASE__   ( self		:		List[str]    ):





         """simple docstring"""



         move_cursor(len(self.choices    ) - self.position  ,				'''DOWN'''    )
         return self.position






     @input.mark(KEYMAP['''interrupt''']    )
     def    SCREAMING_SNAKE_CASE__   ( self		:		Tuple    ):





         """simple docstring"""



         move_cursor(len(self.choices    ) - self.position  ,				'''DOWN'''    )
         raise KeyboardInterrupt






     @input.mark_multiple(*[KEYMAP[str(a    )] for number in range(10    )]    )
     def    SCREAMING_SNAKE_CASE__   ( self		:		Dict    ):





         """simple docstring"""



         __lowerCamelCase		=  int(chr(self.current_selection    )    )
         __lowerCamelCase		=  index - self.position
         if index == self.position:
             return
         if index < len(self.choices    ):
             if self.position > index:
                 self.move_direction(Direction.UP  ,				-movement    )
             elif self.position < index:
                 self.move_direction(Direction.DOWN  ,				a    )
             else:
                 return
         else:
             return






     def    SCREAMING_SNAKE_CASE__   ( self		:		List[str]  ,				a		:		int = 0    ):





         """simple docstring"""



         if self.prompt:
             linebreak()
             forceWrite(self.prompt  ,				'''\n'''    )
             if in_colab:
                 forceWrite('''Please input a choice index (starting from 0), and press enter'''  ,				'''\n'''    )
             else:
                 forceWrite('''Please select a choice using the arrow or number keys, and selecting with enter'''  ,				'''\n'''    )
         __lowerCamelCase		=  default_choice
         for i in range(len(self.choices    )    ):
             self.print_choice(a    )
             forceWrite('''\n'''    )
         move_cursor(len(self.choices    ) - self.position  ,				'''UP'''    )
         with cursor.hide():
             while True:
                 if in_colab:
                     try:
                         __lowerCamelCase		=  int(builtins.input()    )
                     except ValueError:
                         __lowerCamelCase		=  default_choice
                 else:
                     __lowerCamelCase		=  self.handle_input()
                 if choice is not None:
                     reset_cursor()
                     for _ in range(len(self.choices    ) + 1    ):
                         move_cursor(1  ,				'''UP'''    )
                         clear_line()
                     self.write_choice(a  ,				'''\n'''    )
                     return choice


import math






def   lowerCAmelCase_						(					_snake_case      :  float      ,   _snake_case      :  float   )				->		float:







	'''simple docstring'''


	return math.pow(_snake_case      ,   2   ) - a






def   lowerCAmelCase_						(					_snake_case      :  float   )				->		float:







	'''simple docstring'''


	return 2 * x






def   lowerCAmelCase_						(					_snake_case      :  float   )				->		float:







	'''simple docstring'''


	__magic_name__		:		Optional[int]	   =     2.0

	while start <= a:
		__magic_name__		:		str	   =     math.pow(_snake_case      ,   2   )

	return start






def   lowerCAmelCase_						(					_snake_case      :  float      ,   _snake_case      :  int = 9999      ,   _snake_case      :  float = 0.00_000_000_000_001   )				->		float:







	'''simple docstring'''


	if a < 0:
		raise ValueError("math domain error"   )

	__magic_name__		:		Optional[int]	   =     get_initial_point(_snake_case   )

	for _ in range(_snake_case   ):
		__magic_name__		:		int	   =     value
		__magic_name__		:		str	   =     value - fx(_snake_case      ,   _snake_case   ) / fx_derivative(_snake_case   )
		if abs(prev_value - value   ) < tolerance:
			return value

	return value


if __name__ == "__main__":
				from doctest import testmod

				testmod()
