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.
JavaScript
x
12
12
1
class Solution:
2
def findFinalValue(self, nums: List[int], original: int) -> int:
3
if original in nums:
4
for original in nums:
5
original = original * 2
6
print(original)
7
else:
8
print(original)
9
10
yeyo = Solution()
11
yeyo.findFinalValue()
12
Advertisement
Answer
I think this is what you’re trying to accomplish?
JavaScript
1
18
18
1
from typing import List
2
3
class Solution:
4
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
5
_done = False # Created a bool value to act as a switch to disable the while loop
6
original_number = search_value # saving the original value since im recycling the original var below
7
while _done is False: # Keep doing until the switch above is turned off
8
if search_value in number_list: # The condition you needed set
9
search_value *= 2 # that action if condition is met
10
else:
11
_done = True # the off "switch"
12
return "Original Number: {} Search value multiplied up to: {}".format(original_number, search_value) # returns both using a formatted string
13
#return original_number # Uncomment this line and delete the other return to only return the original number
14
15
16
yeyo = Solution()
17
yeyo.findFinalValue([1,2,3,4,5,6,7,8,9,10], 2)
18