Let’s Learn 3. Modules Saenthong School, January – February 2016

Slides:



Advertisements
Similar presentations
JavaScript Chapter 6 Note new scoring. spin.js (page 67) function spin() function spin() { var obj_style = document.getElementById("d1").style; var obj_style.
Advertisements

Noadswood Science,  To know how to use Python to produce windows and colours along with specified co-ordinates Sunday, April 12, 2015.
Building Java Programs
Return values.
Arithmetic in Pascal (2) Arithmetic Functions Perform arithmetic calculations Gives an argument to the function and it returns the result.
COMPSCI 105 S Principles of Computer Science
Lecture 6 MATLAB functions Basics of Built-in Functions, Help Feature, Elementary Functions (e.g., Polynomials, Trigonometric Functions), Data Analysis,
Strings, if/else, return, user input
Week 3 parameters, return, math, graphics Special thanks to Scott Shawcroft, Ryan Tucker, and Paul Beck for their work on these slides. Except where otherwise.
Week 3 parameters and graphics Special thanks to Scott Shawcroft, Ryan Tucker, and Paul Beck for their work on these slides. Except where otherwise noted,
Copyright 2006 by Pearson Education 1 Building Java Programs Chapter 3: Parameters, Return, and Interactive Programs with Scanner.
Week 3 parameters, return, math, graphics Special thanks to Scott Shawcroft, Ryan Tucker, and Paul Beck for their work on these slides. Except where otherwise.
Introduction to TouchDevelop
B.A. (Mahayana Studies) Introduction to Computer Science November March Logo (Part 1) An introduction to Logo: drawing, moving,
Microsoft® Small Basic The Math Object Estimated time to complete this lesson: 1 hour.
INTRODUCTION TO PYTHON PART 1 CSC482 Introduction to Text Analytics Thomas Tiahrt, MA, PhD.
EXAMPLE 1 Use an inverse tangent to find an angle measure
Maths Methods Trigonometric equations K McMullen 2012.
Introduction to Scratch!
Hello! Keep watching … I’ll show you how to use a mouse.
Programming Training kiddo Main Points: - Python Statements - Problems with selections.
Computer Science 111 Fundamentals of Programming I Introduction to Graphics.
Warm- Up 1. Find the sine, cosine and tangent of  A. 2. Find x. 12 x 51° A.
Art 321 Lecture 7 Dr. J. Parker. Programming In order to ‘make things happen’ on a computer, you really have to program it. Programming is not hard and.
Class 2 Introduction to turtle graphics
Introduction to TouchDevelop
Introduction to Using the Notebook 10 Software for SMART Board Day 2 LIVINGSTON PARISH PUBLIC SCHOOLS Facilitated by S. Waltman.
Week 3 parameters and graphics Special thanks to Scott Shawcroft, Ryan Tucker, and Paul Beck for their work on these slides. Except where otherwise noted,
Introduction As programmers, we don’t want to have to implement functions for every possible task we encounter. The Standard C library contains functions.
Inserting Hyperlinks  Purpose : Enables viewers to click the link and move directly to a slide  Directions : Make one link on slide one to move to each.
The Microsoft ® Mouse Mischief ™ add-in works with Microsoft ® PowerPoint ® 2010 or Microsoft ® Office PowerPoint ® Download and install the Mouse.
5. Loops 1 Let’s Learn Saenthong School, January – February 2016 Teacher: Aj. Andrew Davison, CoE, PSU Hat Yai Campus
7. Lists 1 Let’s Learn Saenthong School, January – February 2016 Teacher: Aj. Andrew Davison, CoE, PSU Hat Yai Campus
1. Starting 1 Let’s Learn Saenthong School, January – February 2016 Teacher: Aj. Andrew Davison, CoE, PSU Hat Yai Campus
Pablo Revelo. Birds: to 3birds pu home pd lt 80 pu fd 250 pd setpensize 2 setpc "white st bird pu bk random 100 bird pu lt 90 fd random 40 bird ht.
If/else, return, user input, strings
8. Functions 1 Let’s Learn Saenthong School, January – February 2016 Teacher: Aj. Andrew Davison, CoE, PSU Hat Yai Campus
Turtle Graphics Let’s see what we can draw on Python!
DRAWING CHALLENGES IN MS WORD. GET READY Start MS Word Make sure you have the Home Tab selected You will be using these tools.
Turtle Graphics Lesson 2 1. There are 3 homeworks to complete during the six lessons of this unit. Your teacher will let you know when a homework has.
4. If Statements 1 Let’s Learn Saenthong School, January – February 2016 Teacher: Aj. Andrew Davison, CoE, PSU Hat Yai Campus
LOGO WHAT IS IT? HOW TO USE IT AND HOW USEFUL CAN IT BE?
What is it? How to use it and how useful can it be?
3. Drawing Let’s Learn Saengthong School, June – August 2016 Teacher: Aj. Andrew Davison, CoE, PSU Hat Yai Campus
PowerPoint Project 1 These instructions will tell you what TAB you need to go to, but will not give you pictures of the COMMAND buttons you need. 1.Go.
EXAMPLE 1 Use an inverse tangent to find an angle measure Use a calculator to approximate the measure of A to the nearest tenth of a degree. SOLUTION Because.
CSE 110: Programming Language I Afroza Sultana UB 1230.
5. Loops 1 Make a program do things over-and-over-and over again. Counting loops; Conditional loops. Games: guessing, ghost, hangman Computer.
Get Microsoft Mouse Mischief
Get Microsoft Mouse Mischief
Using the Python Turtle
Module 2: Investigation 2
Let’s Learn 12. Packaging a Game Saengthong School, June – August 2016
Some Useful MATLAB Functions
Fundamentals of Programming I Introduction to Graphics
Graphics CIS 40 – Introduction to Programming in Python
Let’s Learn 2. Installing Pygame
Going Green By Ima Librarian
9. Drawing Let's Learn Python and Pygame
Fundamentals of Programming I Introduction to Graphics
5. Loops Let's Learn Python and Pygame
Learning to program with Logo
Let's Learn Python and Pygame
8. Starting Pygame Let's Learn Python and Pygame
Let's Learn Python and Pygame
BSc in Digital Media, PSUIC
Chap. 3 Functions Start Python IDLE (Shell) and open a new file.
POWER POINT WHY HAVE WE USE THIS PROGRAM? TO SHOW YOUR STUDY..
Section 3 Programming with Turtle Graphics
What are variables? Using input()
Presentation transcript:

Let’s Learn 3. Modules Saenthong School, January – February 2016 Teacher: Aj. Andrew Davison, CoE, PSU Hat Yai Campus E-mail: ad@fivedots.coe.psu.ac.th 3. Modules Using modules to give Python even more POWER Look at built-in modules: random, math, turtle, winsound Start turtle graphics. Look at installing easygui using pip Using easygui

1. What is a Module? A module is a program that adds extra features to Python e.g. for 3D graphics, for writing games There are lots of modules that come with Python called built-in or standard modules It is easy to add more called third-party modules

Python's Design A small … plus lots language … of modules turtle math winsound

2. Using the random Module

List Modules Already in Python

Help on any Modules using the word "random"

Module Documentation click on "modules"

Information on random Look under 'r' in the Python Module Index

3. The math Module import math or from math import * Function name Description abs(value) absolute value ceil(value) rounds up cos(value) cosine, in radians degrees(value) convert radians to degrees floor(value) rounds down log(value, base) logarithm in any base log10(value) logarithm, base 10 max(value1, value2, ...) larger of two (or more) values min(value1, value2, ...) smaller of two (or more) values radians(value) convert degrees to radians round(value) nearest whole number sin(value) sine, in radians sqrt(value) square root tan(value) tangent Constant Description e 2.7182818... pi 3.1415926... import math or from math import *

Information on math Look under 'm' in the Python Module Index

4. The turtle Module The turtle moves about in a drawing window with a pen for drawing lines. The turtle can be told to turn a number of degrees, move a distance, move to a new position, and change its pen's color and line width If the turtle’s pen is down, it draws a line; otherwise, it moves without drawing

The Turtle Drawing Window 90° The turtle is an icon Initial position: (0, 0) Initial direction: East (0°) Color: black Line width: 1 pixel Pen: down (ready to draw) x-axis (0,0) 180° 0° 270° y-axis

Create a Turtle Tell Python to add the Turtle command to its built-in commands >>> from turtle import Turtle >>> sleepy = Turtle()

Some turtle Commands home() # Return to (0, 0) and 0° (east) down() # Enable drawing up() # Disable drawing forward(distance) # Go distance in current direction goto(x, y) # Go to (x, y) left(degrees) # Add degrees to current direction setheading(degrees) # Make degrees the new direction width(width) # Set width of pen in pixels color(color) # Red, green, blue, etc.

Move a Distance Move 50 pixels in the current direction. >>> from turtle import Turtle >>> sleepy = Turtle() >>> sleepy.forward(50) Move 50 pixels in the current direction. There's also a backward() command.

Turning Left or Right A turtle can turn left or right by a number of degrees e.g. sleepy.left(45) This angle is offset from the turtle's current forward direction. left(45) forward left(45) forward

Tell the turtle to draw a square Square.py

Draw a House House.py

A Blue Equilateral Triangle Triangle.py

Why those Angle? Why does the square need 4 turns of 90*? Why does the triangle need 3 turns of 120*? Look for a pattern... 4 * 90 == 3 * 120 == 360 degrees How would you get the turtle to draw a five-sided shape (a pentagon)?

A Faster Turtle Square.py

Filling the Shape with Color Square.py

Drawing (Bits of) Circles Circles.py

Writing Text HelloWorld.py

goto(x,y) The usual turtle window has -200 ≤ x ≤ 200 and Also used in setpos(x,y)

Print Information about the Turtle >>> from turtle import Turtle >>> sleepy = Turtle() >>> sleepy.goto(0, 50) >>> print(sleepy.position(), sleepy.pencolor(), \ sleepy.heading(), sleepy.isdown()) (0.00,50.00) black 0.0 True

Information on turtle Look under 't' in the Python Module Index

6. Windows Sound: winsound

Have you seen Star Wars? Run the programs: Python Gangnam Style: March.py playSound.py Python Gangnam Style: Gangnam.py

7. Getting More Modules https://pypi.python.org/pypi I'll search for "GUI"

lots more off the bottom of this picture

the "easygui" looks good; click on it for lots more details

Info on easygui The easygui webpage: An easygui tutorial: http://easygui.sourceforge.net/ you can also download easygui from there then use pip on the downloaded zip file An easygui tutorial: http://www.ferg.org/easygui/tutorial.html

8. Installing a PyPI Module Use the pip program that comes as part of the Python download. Use it from the Command window.

Use pip to Search PyPI

Use pip to Install easygui

More pip commands pip help pip list gives help on using pip pip list lists the extra (thitd-party) modules that you have added to Python pip install <downloaded file> installs a module that you've downloaded yourself

9. Use easygui in Python

Use easygui with Less Typing Tell Python to add all the easygui commands to Python's built-in commands

Getting the "OK" Input

Dialog Box with Buttons IceButtons.py

(Ugly) Choice Box IceChoice.py

Text Input IceEnter.py

Response