-1

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?

1
  • 2
    Assuming this is all of your code: You need to call your function GetNum and pass the argument Text to it when calling. Commented Feb 17, 2016 at 19:05

4 Answers 4

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.

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

1

make the code as such, no function

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

4 Comments

You will have an infinite loop with this.
no, just hit enter without entering any text and you are good. just tried it
That is the exception. You would probably just want to convert the input into an int and have it do something, otherwise its meaningless.
i suppose it depends on the context
-1

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.