官术网_书友最值得收藏!

Write and run your first program in the command line

Now that you are set up, it is time to write your first line of code in Python! This line of code is almost a tradition for people who are programming for the first time, and it allows us to use one of the most basic, but most useful, functions in the Python language.

First, you need to start running a Python shell. On Mac or Linux, open your terminal and type this:

python

In the Mac or Ubuntu terminal, your resulting Python shell will look like this:

>>>

In Windows, type Python in the search bar at the bottom of the page. Then, select Python 2.7.11 from your apps. You will also have a Python shell open:

>>>

Once you see this symbol, your computer is now ready to work with the Python code. In your terminal or IDLE, type the following:

>>>print("Hello, world!")

Once you have typed this, double-check to make sure that all of the spaces are exactly as they've been written. In Python, every space actually matters. Every punctuation mark matters. Once you have checked your code, hit Enter.

What is your result or the output of your code? If the output looks like the following image, then great! You typed all of your code properly so the computer will understand what you want it to do. The expected output will be similar to what is shown here:

For Windows users, the output window will look like this:

So, if your output does not look like the preceding code, you need to figure out what's wrong with it. Here are some of the reasons for this:

  • Did you make a typing error?
  • Did you forget to use parenthesis or round brackets () for the words 'Hello, world!'?
  • Did you forget to use the ''single quotation marks for Hello, world!?

If you still have a problem, compare your code to the sample input code and fix any mistakes. Then, try to run the code again.

Note

Python is what is called a case-sensitive language. Python cares about uppercase, lowercase, and whitespace. You need to watch what you type. You might get some strange messages from your computer if you make a typing mistake or a syntax error.

主站蜘蛛池模板: 咸阳市| 鱼台县| 泽普县| 甘泉县| 如皋市| 永善县| 漯河市| 施甸县| 时尚| 枝江市| 安康市| 永和县| 万年县| 内丘县| 延寿县| 闽清县| 福鼎市| 平南县| 沈丘县| 邵武市| 嘉兴市| 鹰潭市| 双柏县| 大新县| 渝中区| 武隆县| 资中县| 邵武市| 达孜县| 登封市| 正镶白旗| 财经| 莱西市| 西峡县| 巴林右旗| 新民市| 乃东县| 定襄县| 潜山县| 四川省| 措美县|