0

As you know input returns a string.

listOfNums = input("Type Numbers ")

def calcR(num1, num2):
    return 1 / ((1 / num1) + (1 / num2))

but here in reduce I need a list of numbers to place it in the function.

result = round(reduce(calcR, list(listOfNums)), 5)

If I run the app like that and type numbers in the input prompt I will have an error that tells me that you entered a string value and the function needs an integer value

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
  • Do you know how to split a string into a list of strings using a space delimiter? Do you know how to convert a string to an integer? Put those two things together. – Barmar Sep 11 '21 at 21:57

1 Answers1

0

I believe you are looking for map:

from functools import reduce


listOfNums = input("Type Numbers ")
m = list(map(int, listOfNums))

def calcR(num1, num2):
    return 1 / ((1 / num1) + (1 / num2))

result = round(reduce(calcR, m), 5)
rv.kvetch
  • 9,940
  • 3
  • 24
  • 53