笨办法学Python习题1 第一个程序

来源:互联网 发布:java windows 路径 编辑:程序博客网 时间:2024/06/06 01:18

通过习题0的学习,可以通过终端在电脑上建立文件夹和文件,并用TextWrangler打开并编辑。

1,建立文件夹,打开mac的终端,敲入一下指令:

mkdir /users/simengred/mystuff ---- 在文件夹users/simengred下建立一个名叫mystuff的文件夹

cd /users/simengred/mystuff     -----切换到mystuff文件夹路径下

touch ex1.py   ------建立一个名为ex1.py的python文件

通过以上指令,我们就成功在路径/users/simengred/mystuff的路径下建立了一个ex1.py的文件

2,接下来我们打开TextWrangler软件,Command+O打开这个ex1.py的文件

并写入一下代码:

hello againi like typing thisthis is funYay!printingi'd much rather you 'not'.i "I said" do not touch thissimengred's first program

3,点击Command+s保存程序

4,在用终端执行以上程序。如果你没有关闭终端,那目前终端的路径仍然在mystuff的路径。如果已经退出,需要重新切换至mystuff路径下:

①先切换至mystuff文件目录下:cd /users/simengred/mystuff

②执行ex1.py:python ex1.py

5,执行结果如下:

hello againi like typing thisthis is funYay!printingi'd much rather you 'not'.i "I said" do not touch thissimengred's first program



原创粉丝点击