Our first program - Programming
学习要点
- 什么是编程语言(EN: programming language)
- 初步了解以下基本概念
- 指令(EN: instruction)
- 语句(EN: statement)
- 函数、方法、过程(EN: function, method, or procedure)
- 参数(EN: parameter)
- 输出字符串
代码示例
C++ Sample Code 隐藏/显示注释
Python Sample Code
作业
- 在屏幕上用“-”和“|”这两个英文字符打印出一个长方形图案。
- 在屏幕上打出爱心的图片字样。可以用*表示爱心图片的边界。
Instroduction
When we write a computer program, we’re giving the computer a set of instructions for what we want it to do. Just like we can tell a dog to “sit” or “beg”, we can tell a computer to “add” or “print”. A computer isn’t as furry as a dog, but fortunately, it’s a lot more reliable! And just a bit better at math…
Try it
There are many languages we can use to write computer programs.
Let’s start with a simple “Hello World” program, the first program of many new programmers. Our goal is to get the computer to display “Hello World” somewhere on the screen. Please check above C++ and Python code.
How does it work?
Now let’s break down our 1-line python program:
print("Hello, World!")
That line of code is called a statement. All programs are made up of statements, and each statement is an instruction to the computer about something we need it to do.
The print() command is also called a function, method, or procedure. That line tells the computer to call the procedure named print that knows how to display output in a console.
The print() procedure expects a single parameter which specifies what text the computer should display. In this program, the value passed in is “Hello, World!”, so that is what’s displayed.
本页面采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可。
致谢:Khan Academy - AP® Computer Science Principles