They gave me the first two lines of code. I thought I knew how to do it but I don’t really understand what I’m missing.
class Solution:
def findFinalValue(self, nums: List[int], original: int) -> int:
if original in nums:
for original in nums:
original = original * 2
print(original)
else:
print(original)
yeyo = Solution()
yeyo.findFinalValue()
Advertisement
Answer
I think this is what you’re trying to accomplish?
from typing import List
class Solution:
def findFinalValue(self, number_list: List[int] = [1,2,3,4,5,6,7,8,9,10], search_value: int = 9) -> int: # Added some default values to test without adding parameters
_done = False # Created a bool value to act as a switch to disable the while loop
original_number = search_value # saving the original value since im recycling the original var below
while _done is False: # Keep doing until the switch above is turned off
if search_value in number_list: # The condition you needed set
search_value *= 2 # that action if condition is met
else:
_done = True # the off "switch"
return "Original Number: {} Search value multiplied up to: {}".format(original_number, search_value) # returns both using a formatted string
#return original_number # Uncomment this line and delete the other return to only return the original number
yeyo = Solution()
yeyo.findFinalValue([1,2,3,4,5,6,7,8,9,10], 2)