0

I have this simple python program:

def GetNum (Text):
    x = input("Input something: ")
    while (x > 0):
        x = input("Input something: ")

    print x

And I want to run that through terminal, but when I do the command:

python ./test.py

or if I run

python test.py

Nothing happens. The terminal just goes back to normal, as if no command was ever executed.

The file is located under Documents/Python and I am in that directory when I am running the command. Am I missing something here as to why this is not working?

Alastair McCormack
  • 26,573
  • 8
  • 77
  • 100
Anderology
  • 147
  • 1
  • 2
  • 9
  • 2
    Assuming this is all of your code: You need to call your function `GetNum` and pass the argument `Text` to it when calling. – albert Feb 17 '16 at 19:05

4 Answers4

5

Your program does not output anything because you are never calling your function.

This will do what you expect:

def GetNum():
    x = int(input("Input something: "))
    while (x > 0):
        x = int(input("Input something: "))

    print(x)

GetNum()

I removed the function argument Text, added a call to the GetNum function and added type conversions from str to int for both input() calls.

pp_
  • 3,435
  • 4
  • 19
  • 27
4

You haven't called your GetNum function.

You need to add the following to the bottom of your script:

GetNum(None)

Text is not used, so None is a null object.

You may want to read up on defining functions, function arguments and calling functions, which is out-of-scope for StackOverflow - See http://www.tutorialspoint.com/python/python_functions.htm

Alastair McCormack
  • 26,573
  • 8
  • 77
  • 100
1

make the code as such, no function

x = input("Input something: ")
while (x):
    x = input("Input something: ")

print x
yoyoyoyo123
  • 2,362
  • 2
  • 22
  • 36
-1

There are multiple ways But the easiest one is to call the function i.e GetNum (some text)