The main Function, introcs Library, and Prompting

Slides:



Advertisements
Similar presentations
Programming in python Lesson 2.
Advertisements

Chapter 2 Writing Simple Programs
JavaScript with Input & Output Step 1: Use tags JavaScript Template.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #002 (January 17, 2015)
PYTHON. Python is a high-level, interpreted, interactive and object- oriented scripting language. Python was designed to be highly readable which uses.
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
Chapter 1 Working with strings. Objectives Understand simple programs using character strings and the string library. Get acquainted with declarations,
Lesson 4 Using Variables in Python – Creating a Simple ChatBot Program.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
1 C++ Programming Basics Chapter 1 Lecture CSIS 10A.
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 1 Simple Python Programs Using Print, Variables, Input.
CSC 110 Using Python [Reading: chapter 1] CSC 110 B 1.
Exam 1 Review Instructor – Gokcen Cilingir Cpt S 111, Sections 6-7 (Sept 19, 2011) Washington State University.
Passing Arguments, Local/Global Variables Writing Functions( ) (Part 2)
Python Let’s get started!.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
Creating a mystic meg program A simple program asking the user questions and using their answers to build up a fortune telling in a list.
Introduction to Functions CSIS 1595: Fundamentals of Programming and Problem Solving 1.
1. COMPUTERS AND PROGRAMS Rocky K. C. Chang September 6, 2015 (Adapted from John Zelle’s slides)
Programming for GCSE Topic 8.1: Functions T eaching L ondon C omputing William Marsh School of Electronic Engineering and Computer Science Queen Mary University.
Control Structures WHILE Statement Looping. S E Q C E N U E REPITITION …a step or sequence of steps that are repeated until some condition is satisfied.
Quiz 3 Topics Functions – using and writing. Lists: –operators used with lists. –keywords used with lists. –BIF’s used with lists. –list methods. Loops.
Part 1 Learning Objectives To understand that variables are a temporary named location to store data and that programmers work with different data types.
More about Iteration Victor Norman CS104. Reading Quiz.
JavaScript: Conditionals contd.
Chapter 2 Writing Simple Programs
what is computer programming?
Topic: Iterative Statements – Part 1 -> for loop
Python: Experiencing IDLE, writing simple programs
Python Let’s get started!.
Topic: Python’s building blocks -> Statements
Programming Fundamental
Variables, Expressions, and IO
Functions CIS 40 – Introduction to Programming in Python
Python I/O.
Python Primer 2: Functions and Control Flow
Please use speaker notes for additional information!
COMP 110 Loops, loops, loops, loops, loops, loops…
Programming Funamental slides
CISC101 Reminders Assn 3 due tomorrow, 7pm.
Program Flow Control Selection & repetition
Functions In Matlab.
Lecture Notes 8/24/04 (part 2)
Loops CIS 40 – Introduction to Programming in Python
Hello World! Syntax.
Variables and Expressions
We are starting JavaScript. Here are a set of examples
For this assignment, copy and past the XHTML to a notepad file with the .html extension. Then add the code I ask for to complete the problems.
CSCI N207 Data Analysis Using Spreadsheet
A LESSON IN LOOPING What is a loop?
CISC101 Reminders Assignment 3 due next Friday. Winter 2019
COMPUTER PROGRAMMING SKILLS
Basic Lessons 5 & 6 Mr. Kalmes.
Announcements Lab 3 was due today Assignment 2 due next Wednesday
Introduction to Python
Lesson 02: Introduction to Python
Unit 1: Intro Lesson 4: Output.
CISC101 Reminders Assignment 3 due today.
What you need to do… Drag the pieces of code into the correct order like you can see in the EXAMPLE below. print ( “ int input ) = + Hello world chr ord.
statement. Another decision statement, , creates branches for multi-
 A function is a named sequence of statement(s) that performs a computation. It contains  line of code(s) that are executed sequentially from top.
while Loops Looping Control Statement
Functions Overview © 2018 Kris Jordan.
if-then-else Conditional Control Statement
The return Statement © 2018 Kris Jordan.
Parameters and Arguments
The for Loop © 2018 Kris Jordan.
Arrays: Iteration Working through an array algorithmically.
Data Types and Expressions
Getting Started in Python
Presentation transcript:

The main Function, introcs Library, and Prompting © 2018 Kris Jordan

The Structure of a Simple Program (1 / 4) We begin with importing functionality from libraries Here we're importing a function named print from the introcs library The introcs library includes many other functionalities, too, like the ability to prompt for input. // Hello World Demo import { print } from "introcs"; export let main = async () => { print("hello, world"); }; main();

The Structure of a Simple Program (2 / 4) The programs we write will have a main function defined in this way. This definition contains the instructions we want the program to follow ( print "hello, world" ) Soon you will learn what each of these words and symbols means. For now, we will treat the main function's definition as magic. // Hello World Demo import { print } from "introcs"; export let main = async () => { print("hello, world"); }; main();

The Structure of a Simple Program (3 / 4) The last line of code in our program calls, or invokes, the main function This line tells our main function to proceed so our program begins. You will see this in every program, as well. It should be the last statement in a file that contains a main function definition. // Hello World Demo import { print } from "introcs"; export let main = async () => { print("hello, world"); }; main();

The Structure of a Simple Program (4 / 4) Initially, you will write code inside of the main function. These are the instructions your program will follow. Soon, you will learn to write functions defined outside of main. // Hello World Demo import { print } from "introcs"; export let main = async () => { print("hello, world"); }; main();

Prompting for Input (1/2) The introcs library provides 3 functions to prompt for input: promptString promptNumber promptBoolean Each will ask the user to enter data of the given type To use a prompt function, you must import it from the introcs library: import { promptString } from "introcs"; You'll often need to import more than one function from a library. There is a convenient way of doing this with a comma-separated list of functions: import { print, promptString, promptNumber } from "introcs";

Prompting for Input (2/2) When prompting, the program must await user input. It is as if our program pauses or, more technically, blocks, at the prompt. 3 2 1 age = await promptNumber("What is your age?"); The promptNumber function is called and will ask the question "What is your age?" The program awaits the user's input. Once the user has input data, the right hand side of the assignment statement evaluates to the data entered and is, finally, assigned to the age variable.