The document provides an introduction to programming and explains why learning to write programs is useful. It discusses how computers are built to continuously ask "what's next?" and how programmers add operating systems and applications to create personal digital assistants. It describes computer hardware components like the CPU, memory, and input/output devices. It also explains key programming concepts like syntax, logic, inputs, outputs, conditions, repetition, and reusing code. Common error types like syntax errors, logic errors, and semantic errors are also outlined.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
9 views16 pages
1 Introduction
The document provides an introduction to programming and explains why learning to write programs is useful. It discusses how computers are built to continuously ask "what's next?" and how programmers add operating systems and applications to create personal digital assistants. It describes computer hardware components like the CPU, memory, and input/output devices. It also explains key programming concepts like syntax, logic, inputs, outputs, conditions, repetition, and reusing code. Common error types like syntax errors, logic errors, and semantic errors are also outlined.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16
Introduction
Why should you learn to write programs?
• The hardware in our current-day computers is essentially built to continuously ask us the question, “What would you like me to do next?” • Programmers add an operating system and a set of applications to the hardware and we end up with a Personal Digital Assistant that is quite helpful and capable of helping us do many different things. Why should you learn to write programs? • Our computers are fast and have vast amounts of memory and could be very helpful to us if we only knew the language to speak to explain to the computer what we would like it to “do next”. • For a computer, reading and understanding text from a piece of paper is hard to do but counting the words and telling you how many times the most used word was used is very easy. • This very fact that computers are good at things that humans are not is why you need to become skilled at talking “computer language”. Computer hardware architecture Computer hardware architecture • The Central Processing Unit (or CPU) is the part of the computer that is built to be obsessed with “what is next?” • The Main Memory is used to store information that the CPU needs in a hurry. But the information stored in the main memory vanishes when the computer is turned off. • The Secondary Memory is also used to store information, but it is much slower than the main memory. The advantage of the secondary memory is that it can store information even when there is no power to the computer. • The Input and Output Devices are simply our screen, keyboard, mouse, microphone, speaker, touchpad, etc. They are all of the ways we interact with the computer. Computer hardware architecture • As a programmer you will mostly be “talking” to the CPU and telling it what to do next. Sometimes you will tell the CPU to use the main memory, secondary memory, network, or the input/output devices. • You need to be the person who answers the CPU’s “What next?” question and issue a command three billion times per second. • So instead, you must write down your instructions in advance. We call these stored instructions a program and the act of writing these instructions down and getting the instructions to be correct programming. Understanding programming • First, you need to know the programming language (Python) - you need to know the vocabulary and the grammar. You need to be able to spell the words in this new language properly and know how to construct well-formed “sentences” in this new language. • Second, you need to “tell a story”. In writing a story, you combine words and sentences to convey an idea to the reader. In programming, our program is the “story” and the problem you are trying to solve is the “idea”. Words and sentences • Unlike human languages, the Python vocabulary is actually pretty small. We call this “vocabulary” the “reserved words”. • When Python sees these words in a Python program, they have one and only one meaning to Python. • Later as you write programs you will make up your own words that have meaning to you called variables. • You will have great latitude in choosing your names for your variables, but you cannot use any of Python’s reserved words as a name for a variable. Words and sentences • We will learn these reserved words and how they are used in good time, but for now we will focus on the Python equivalent of “speak” (in human-to-dog language). The nice thing about telling Python to speak is that we can even tell it what to say by giving it a message in quotes: Conversing with Python Terminology: interpreter and compiler • Python is a high-level language intended to be relatively straightforward for humans to read and write and for computers to read and process. Other high-level languages include Java, C++, PHP, Ruby, Basic, Perl, JavaScript, and many more. • The CPU understands a language we call machine language. Machine language is very simple and frankly very tiresome to write because it is represented all in zeros and ones. Terminology: interpreter and compiler • Machine language seems quite simple on the surface, given that there are only zeros and ones, but its syntax is even more complex and far more intricate than Python. • Instead we build various translators to allow programmers to write in high-level languages like Python and these translators convert the programs to machine language for actual execution by the CPU. • Programs written in high-level languages can be moved between different computers by using a different interpreter on the new machine or recompiling the code to create a machine language version of the program for the new machine. Terminology: interpreter and compiler • These programming language translators fall into two general categories: (1) interpreters and (2) compilers. • An interpreter reads the source code of the program as written by the programmer, parses the source code, and interprets the instructions on the fly. • A compiler needs to be handed the entire program in a file, and then it runs a process to translate the high-level source code into machine language and then the compiler puts the resulting machine language into a file for later execution. The building blocks of programs • Input get data from the “outside world”. This might be reading data from a file, or even some kind of sensor like a microphone or GPS. In our initial programs, our input will come from the user typing data on the keyboard. • Output display the results of the program on a screen or store them in a file or perhaps write them to a device like a speaker to play music or speak text. • Sequential execution perform statements one after another in the order they are encountered in the script. The building blocks of programs • Conditional execution check for certain conditions and then execute or skip a sequence of statements. • Repeated execution perform some set of statements repeatedly, usually with some variation. • Reuse write a set of instructions once and give them a name and then reuse those instructions as needed throughout your program. What could possibly go wrong? • Syntax errors - These are the first errors you will make and the easiest to fix. A syntax error means that you have violated the “grammar” rules of Python. • Logic errors - A logic error is when your program has good syntax but there is a mistake in the order of the statements or perhaps a mistake in how the statements relate to one another. • Semantic errors - A semantic error is when your description of the steps to take is syntactically perfect and in the right order, but there is simply a mistake in the program. The program is perfectly correct but it does not do what you intended for it to do.
Efficacy and Safety of Repeated Subcutaneous Ketamine Injections for Treatment Resistant Depression the KADS Study a Randomised Double Blind Comparator Controlled Trial (1)