PROGRAMMING INFORMATION. PROCEDURES IN PYTHON Procedures can make code shorter, simpler, and easier to write. If you wanted, for example, to use a certain.

Slides:



Advertisements
Similar presentations
CATHERINE AND ANNIE Python: Part 3. Intro to Loops Do you remember in Alice when you could use a loop to make a character perform an action multiple times?
Advertisements

Chapter 41 Variables and JSP Control Structures JavaServer Pages By Xue Bai.
ECS 15 if and random. Topic  Testing user input using if statements  Truth and falsehood in Python  Getting random numbers.
CS0004: Introduction to Programming Repetition – Do Loops.
Chapter 10 Introduction to Arrays
JavaScript Part for Repetition Statement for statement Cpecifies each of the items needed for counter-controlled repetition with a control variable.
Loops (Part 1) Computer Science Erwin High School Fall 2014.
Computer Science 1620 Loops.
Logical Operators Java provides two binary logical operators (&& and ||) that are used to combine boolean expressions. Java also provides one unary (!)
Python November 18, Unit 7. So Far We can get user input We can create variables We can convert values from one type to another using functions We can.
ECE122 L11: For loops and Arrays March 8, 2007 ECE 122 Engineering Problem Solving with Java Lecture 11 For Loops and Arrays.
2015 Pre-Release Practice Click the button to try a random exam-style question. Click on the reveal button to check your answer.
Chapter 5: Control Structures II (Repetition)
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 5: Control Structures II (Repetition)
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
* What kind of loop would I use to complete the following: A. Output all of the prime numbers that are less than 100,000 B. Output the Fibonacci sequence.
Chapter 5: Control Structures II (Repetition)
CHAPTER 5: CONTROL STRUCTURES II INSTRUCTOR: MOHAMMAD MOJADDAM.
EGR 2261 Unit 5 Control Structures II: Repetition  Read Malik, Chapter 5.  Homework #5 and Lab #5 due next week.  Quiz next week.
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
1 4.8The do/while Repetition Structure The do/while repetition structure –Similar to the while structure –Condition for repetition tested after the body.
Lecture 8: Choosing the Correct Loop. do … while Repetition Statement Similar to the while statement Condition for repetition only tested after the body.
Converting Fractions to Decimals
Chapter 4: Loops and Files
Mr. Dave Clausen1 La Cañada High School Chapter 6: Repetition Statements.
University of Palestine software engineering department Introduction to data structures Control Statements: Part 1 instructor: Tasneem Darwish.
New Tools And Workshop Mod & For Loops. Modulo Calculates the remainder (remember long division?) % Examples: 7 % 3 10 % 2 2 % 3 evaluates to 1 evaluates.
Chapter 5: Control Structures II (Repetition). Objectives In this chapter, you will: – Learn about repetition (looping) control structures – Learn how.
AEEE 195 – Repetition Structures: Part B Spring semester 2011.
GAME102 - INTRO WHILE LOOPS G. MacKay. Fundamental Control Structures  STRAIGHT LINE  CONDITIONAL  LOOPS.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 ‏ Control Structures.
CONTENTS Processing structures and commands Control structures – Sequence Sequence – Selection Selection – Iteration Iteration Naming conventions – File.
Python uses boolean variables to evaluate conditions. The boolean values True and False are returned when an expression is compared or evaluated.
Operators Precedence - Operators with the highest precedence will be executed first. Page 54 of the book and Appendix B list C's operator precedence. Parenthesis.
Using Loops. Goals Understand how to create while loops in JavaScript. Understand how to create do/while loops in JavaScript. Understand how to create.
Data Tonga Institute of Higher Education. Variables Programs need to remember values.  Example: A program that keeps track of sales needs to remember.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
Chapter 7 Problem Solving with Loops
Working with Loops, Conditional Statements, and Arrays.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 5: Control Structures II (Repetition)
Fundamental Programming Fundamental Programming More on Repetition.
CS-1010 Dr. Mark L. Hornick 1 Selection and Iteration and conditional expressions.
Topic: Control Statements. Recap of Sequence Control Structure Write a program that accepts the basic salary and allowance amount for an employee and.
COMP Loop Statements Yi Hong May 21, 2015.
Data Handling in Algorithms. Activity 1 Starter Task: Quickly complete the sheet 5mins!
XP Tutorial 3 New Perspectives on JavaScript, Comprehensive1 Working with Arrays, Loops, and Conditional Statements Creating a Monthly Calendar.
UFCFY5-30-1Multimedia Studio Scripting for Interactive Media Further Structures for Branching and Looping.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
Chad’s C++ Tutorial Demo Outline. 1. What is C++? C++ is an object-oriented programming (OOP) language that is viewed by many as the best language for.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 5: Control Structures II (Repetition)
Repetition Looping. Types for while do..while for The for loop allows you to iterate through a variable for a specific range of values. You must supply.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 2: Control Structures (Selection & Repetition)
Lecture 3.1 Operators and Expressions Structured Programming Instructor: Prof. K. T. Tsang 1.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
© 2004 Pearson Addison-Wesley. All rights reserved October 5, 2007 Arrays ComS 207: Programming I (in Java) Iowa State University, FALL 2007 Instructor:
What will each of the following lines print? System.out.println("number" ); number645 System.out.println("number" + (6 + 4)+ 5); number105 System.out.println(6.
Identify the Appropriate Method for Handling Repetition
ARRAYS (Extra slides) Arrays are objects that help us organize large amounts of information.
CSC111 Quick Revision.
Incrementing ITP © Ron Poet Lecture 8.
Engineering Innovation Center
Chapter 8 JavaScript: Control Statements, Part 2
Arithmetic Expressions
Coding Concepts (Basics)
Chapter 5: Control Structures II (Repetition)
Arrays October 6, 2006 ComS 207: Programming I (in Java)
The structure of programming
COMPUTING.
Presentation transcript:

PROGRAMMING INFORMATION

PROCEDURES IN PYTHON Procedures can make code shorter, simpler, and easier to write. If you wanted, for example, to use a certain part of the code numerous times, it is a quick and efficient way of repeating the codes functionality. A procedure needs a name and the program that needs to be completed. For example: def update_display(): print(“Your score:” + str(score)) time.sleep(1) print("High score: " + str(high_score)) time.sleep(1) print("Lives remaining: " + str(lives)) time.sleep(1)

FUNCTIONS IN PYTHON Writing a function is simple. Each function needs a name, values for its calculation, the program for its task, and a value to return. For example, in a dice throwing game you would need: import random def roll_dice(sides): number = random.randint(1,sides) return(number) sides = int(input("How many sides does the dice have?")) throw = roll_dice(sides) print(throw)

QUESTIONS What is the difference between a Function and a Procedure? The difference between a function and a procedure is that a function returns a value and a procedure completes a set task with no returning value. What is a constant and why use it instead of a variable? A constant is a item with a set value, that cannot be changed or manipulated but can instead be referenced. This is better in some cases over a variable as it cannot be accidentally changed. What is the purpose of integer division and modulus? Integer division is used to divide one number by another, but always rounds the answer down to the nearest whole number if it has a remainder. Modulus however, returns the remainder left by a division.

QUESTIONS CONTINUED When should you use a counter controlled loop or a condition controlled loop? A counter controlled loop is a loop that repeats itself for a certain amount of times. It will, for example, loop when the counter is between 1 and 5, and then stop. However, a condition controlled loop loops when a condition is met, for example when a variable is false. Somewhere in the loop it could change to false, thus breaking the loop. What is the difference between Do…While and While…Do? The difference between these is the minimum number of iterations. Where Do…While has to iterate once before it checks the condition for the while, the While…Do checks for a condition before it iterates, thus making its minimum iterations zero.

MORE QUESTIONS….. What is the difference between Declaring and Assigning a Variable? Declaring a Variable is when a certain datatype is declared for the variable, such as a string, Boolean, or an integer. Assigning a Variable is when a value is actually given to the Declared Variable. What is incrementing a variable? Incrementing a variable is when you change a variable by adding something to itself. For example: Age = Age + 1 What is a flag? A Flag is a value that is Boolean, with only two possible values. For example, True or False. The value will have a chance to change during the code, possibly if a condition is met.