1 / 17

Beginning Python Programming for Engineers

Beginning Python Programming for Engineers. Introducing general concepts of prorgramming. Evaluation Criteria for Beginning C. Basic computer science Algorithm design Python Programming Debugging Professional conduct. What is Programming?. Given a problem:

Télécharger la présentation

Beginning Python Programming for Engineers

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Beginning Python Programming for Engineers Introducing general concepts of prorgramming

  2. Evaluation Criteria for Beginning C • Basic computer science • Algorithm design • PythonProgramming • Debugging • Professional conduct

  3. What is Programming? • Given a problem: • Make sure you understand the problem, i.e. It must be well-defined • Find or develop an algorithm to solve the problem • Express that algorithm in a way that the computer can execute it.

  4. Algorithms • In simple terms, an algorithm is a sequence of instructions to solve a problem, such that: • Each instruction is unambiguous, and is something the computer can do. • After an instruction is finished, there is no ambiguity about which instruction is to be executed next. • Execution finishes in a finite number of steps. Think of the computer as a meticulous moron.

  5. Von Neumann machines

  6. Compiled programs

  7. Development Cycle • Design • Edit • Compile and Link • Execute Log Entry describing first ever computer Bug

  8. History of Processing • From the beginning, Processing was designed as a first programming language. It was inspired by earlier languages like BASIC and Logo, as well as our experiences as students and teaching visual arts foundation curricula. The same elements taught in a beginning high school or university computer science class are taught through Processing, but with a different emphasis. Processing is geared toward creating visual, interactive media, so the first programs start with drawing. Students new to programming find it incredibly satisfying to make something appear on their screen within moments of using the software. This motivating curriculum has proved successful for leading design, art, and architecture students into programming and for engaging the wider student body in general computer science classes.

  9. Processing and Computer Engineering •  The Processing approach has also been applied to electronics through the Arduino and Wiring projects. Arduino uses a syntax inspired by that used with Processing, and continues to use a modified version of the Processing programming environment to make it easier for students to learn how to program robots and countless other electronics projects.

  10. Processing Programs on the Computer • Processing Code is stored in files on the computer. It must have the suffix .pyde. • Use the processing editor to edit or create this file. (Could open it in notepad) • Execute or run the code

  11. Building Blocks in Python • Python gives us several building blocks for constructing programs. • Variables and arithmetic expressions • Conditional execution of statements • Controlled repetition of statements • Functions (sub programs) • Printing, getting mouse input • Much more

  12. Our first program • We want a program to print the message ”Hello World”.

  13. Displaying Words in The Gui Window • The text() function is used for writing words to the screen. The letters can be place anywhere on the screen using coordinates. (0,0) top left corner. size(600, 600); background(101); # Set background to gray font = createFont("Sans Serif",12); textFont(font); # the text font will be Serif, size 24 fill(0); #change the color of text to black text("HELLO WORLD",100,100); # Draw text more accurately and efficiently.

  14. Drawing Two Lines # Set the size of the graphical output screen to a width and a height of 200 pixels. size(200, 200); background(102); # Set the background color to greyvalue 102 # Draw two lines. line(0, 0, 200, 200); # Top-left to bottom-right line(0, 200, 200, 0); # Bottom-left to top-right

  15. VAriables • Variables are used for storing values • When creating a variable • Be descriptive • Use single words • Be case sensitive • Be manageable – long enough to be readable, not so long that you can no longer type them.

  16. Assignment Statements • a = 5 • The above is a assignment statement, do not confuse with an equation. • Assignment statements can only have one item on the left of the equal sign. • Example1 a + 5 = 10 is not a legal computer line of code. • Example 2 a = 5 + 10 is a legal computer line of code, a has the value 15.

  17. Variables Example • size(200, 200); • background(0); • stroke(153); • a = 20; • b = 50; • c = a*8; • d = a*9; • e = b-a; • f = b*2; • g = f+e; • line(a, f, b, g); • line(b, e, b, g); • line(b, e, d, c); • line(a, e, d-e, c);

More Related