Class 2. Summer 2012

Downloading and installing Python on your computer.

A discussion of Algorithms and Computers. See the presentation at https://docs.google.com/present/view?id=ddmmhxsn_1260gr2p29cx

Go over chaos program

# File: chaos.py
# A simple program illustrating chaotic behavior.
def main():
     print("This program illustrates a chaotic function")
     x = eval(input("Enter a number between 0 and 1: "))
     for i in range(10):
         x = 3.9 * x * (1 - x)
         print(x)
main()

Translation process. Text to Binary

In Python the program is interpreted. It is translated to binary by the Python language system and then run.

# program to print Hello, World!
def main():
     print("Hello, World!")

main()

In Java the program is translated to an intermediate format called bytecodes. These are interpreted or executed by a Java Virtual Machine.

In C++ the program is compiled for a specific computer system.

#include      // class for stream input/output
using namespace std;    // use the standard namespace

int main ()             //start of main function
{

      // Write 'Hello, World!'  to output

      cout << "Hello,  World! " << endl;

}

Translated to binary or octal (base eight) so it looks like

042577 043114 000401 000001 000000 000000 000000 000000
000002 000003 000001 000000 004630 004005 000064 000000
 016500 000000 000000 000000 000064 000040 000005 000050
 000036 000035 000006 000000 000064 000000 000064 004005
 000000 000000 000240 000000 000240 000000 000005 000000
 000000 000000 000003 000000 000324 000000 000000 000000
 000000 000000 000021 000000 000000 000000 000004 000000
 000000 000000 000001 000000 000000 000000 000000 004005
 000000 000000 006764 000000 006764 000000 000005 000000
 000000 000001 000001 000000 006764 000000 006764 004006 ......
public class HelloWorld {
public static void main( String[] args  )
{
System.out.println("Hello world");
}
}

About Writing Programs

HW for Wednesday:

  • Turn on your source program and answers to questions from “Our first visit to computer lab.”  This can be as an attachment to an email to

ernestackermann AT  gmail.com

replace AT with @  and delete spaces

HomeWork for Thursday:

  • Page 54. Turn in one program – the source and the output of at least three tests. You can send this as an attachment to an email to me. Do any of the exercises 4-6, 7, 10 0r 11.

 

Comments are closed.