cant use def command

MRAB python at mrabarnett.plus.com
Sat Feb 2 16:35:45 EST 2019


On 2019-02-01 15:49, mb1541def 0 wrote:
> 
> Hello,
> I need help on the def command.
> 
> My script:
> 
> Import os
> Test
> 
> def Test():
> print(“test”)
> os.system(“pause”)
> 
> someone please help,it gives me an error in python 3.
> I did everything right.
> 
> --mb1541def
> 
You didn't say what the error was, so I'll just comment on what I can 
see. Some of what I'm seeing might be due to whatever software or forum 
you're using to post the message, messing it up.

1. Capitalization: it should be 'import', not 'Import'.

2. Indentation: the body of the function 'Test' should be indented more 
than its 'def' line.

3. You're referring to 'Test' before it's defined.

4. You're not calling 'Test', but merely referring to it by name. To 
call a function, you need to add parentheses, even if they are empty.

5. Quotes: only plain quotation marks should be used; I'm seeing 'smart' 
quotes.


This should work:

import os

def Test():
     print("test")
     os.system("pause")

Test()



More information about the Python-list mailing list