0

Alright so, I was just learning a different way of inputting data in python, and tried a function:

def userInput():
    n1 = float(input("Enter first number:  "))
    n2 = float(input("Enter second number:  "))
    n3 = float(input("Enter third number:  "))
    print(n1)
    print(n2)
    print(n3)

num1, num2, num3 = userInput()

When I just return n1, n2 and n3, I seem too not encounter a problem, but, when I print the floats, I get this output:

Enter first number:  1
Enter second number:  2
Enter third number:  3
1.0
2.0
3.0
Traceback (most recent call last):
  File "C:/Users/sahar/PycharmProjects/Learningpython/Learning python.py", line 9, in <module>
    num1, num2, num3 = userInput()
TypeError: cannot unpack non-iterable NoneType object

It's a simple question, I'm just curious lol.

Saharsh Aanand
  • 109
  • 1
  • 1
  • 2

1 Answers1

3
def userInput():
    n1 = float(input("Enter first number:  "))
    n2 = float(input("Enter second number:  "))
    n3 = float(input("Enter third number:  "))
    print(n1)
    print(n2)
    print(n3)
    return n1, n2, n3


num1, num2, num3 = userInput()
Pablo Fernandez
  • 103,170
  • 56
  • 192
  • 232
Ratnesh
  • 1,554
  • 3
  • 12
  • 28