Presentation is loading. Please wait.

Presentation is loading. Please wait.

ENGINEERING 1D04 Tutorial 1. WELCOME! What we’re doing today Who am I How to do well What are computer programs Software Development Cycle Pseudo Code.

Similar presentations


Presentation on theme: "ENGINEERING 1D04 Tutorial 1. WELCOME! What we’re doing today Who am I How to do well What are computer programs Software Development Cycle Pseudo Code."— Presentation transcript:

1 ENGINEERING 1D04 Tutorial 1

2 WELCOME!

3 What we’re doing today Who am I How to do well What are computer programs Software Development Cycle Pseudo Code vs. Code Variables Getting Input from a User Python as a Calculator Expressions/Literals Comments Print Statement For loop/range function Practice!

4 Important Info! Who am I? Rachel Lim Just completed third year of Electrical and Biomedical Eng Have TAd for five terms so far, this is my sixth Love to travel Email: limr4@mcmaster.ca

5 How to Succeed Practice, practice, practice! Attend lectures, tutorials and labs Practice before major labs

6 WHAT IS A COMPUTER PROGRAM? Think “Recipe”

7 Software Development Process Analyze the Problem Determine Specifications Create a Design Implement the Design Test/DebugMaintenance

8 Coding Pseudo Code Step 1: Gather Ingredients Step 2: Preheat Oven to 350 F Step 3: Mix Dry Ingredients Step 4: Mix Wet Ingredients Step 5: Combine Wet and Dry Step 6: Bake for 20 minutes Actual Code oven = 350 wet = “milk” + “eggs” dry = “flour + “sugar” mix = wet+dry cookies = string(oven) + mix print cookies

9 Variables/Elements A name for a space to hold information The names are case sensitive Should have some context Names are called identifiers or variables Must begin with a letter or underscore

10 Variables Names Good X Temp Count Velocity Speed height Bad xhgjeo !jigjrejgi A,b,c,d,e,f,g (using letters as all of your variable names can become confusing) for, in, print (reserved words for python – already have another function)

11 Variable Types int: plain integers > 3 long: long integers >3L double: floating point numbers >3.0 complex: real and imaginary part numbers >3+4i string: sequence of characters > hello bool: Boolean (True or False) type() will tell you what type of variable it is

12 Built in Functions abs() : gives you the absolute value of a number abs(-3) = 3 round() : rounds a floating-point number to the nearest integer round(1.2) = 1 int() and float() and string() will change what’s in brackets to its own type int(1.2) = 1, float(1) = 1.0, string(1) = “1”

13 Assigning Variables Correct format: X = 3 So the variable name will be on the LHS with the assigned value on the RHS after an equal sign You can also assign two values to two variables in one line: x,y = 3,4 How would you swap two values? x,y = y,x

14 Getting input from a user Say we would like to ask the user for a number We can use the function “input” Ex. x= input(“please enter a number: ”)

15 Using Python as a Calculator + - / % * ** Remember BEDMAS applies!

16 Integer Division When you divide two integers, the answer can be given as a quotient and a remainder Ex. 26/10 quotient: 2 remainder: 6 When Python divides, only the quotient will be given as the answer Ex. 26/10 = 2  This is known as Integer Division How do we avoid this? Make sure both numbers aren’t integers: 26., 26.0 and/or 10., 10.0 Ex. What will the result be if we type in 95/100?

17 Expressions and Literals Expressions: something that produces or calculates a new value ie. x=3+5 Literal: something that represents a specific value ie. 3

18 Comments Every time you code you should leave comments! Comments help other people understand your code In Python, comments begin with a # This means that Python will ignore anything coming after this symbol

19 Print We use print to output values onto the screen Successive print statements will print on different lines Blank print statements will print blank lines You can use a comma to print multiple values on the same line

20 Definite Loop and Range Function A loop that will run for a specified number of times Takes the format for in : Range is a function that will return a list of numbers REMEMBER! It always starts at zero

21 What will each do? Python Demo Range(6) Range(1,6) Range(4,-1) Range(1,5,2)

22 Practice Quadratic Formula Solve: x 2 -x+6=0 And print it

23 Practice for Major 1


Download ppt "ENGINEERING 1D04 Tutorial 1. WELCOME! What we’re doing today Who am I How to do well What are computer programs Software Development Cycle Pseudo Code."

Similar presentations


Ads by Google