Python Activity 2: Input and Variables in Python

Similar documents
Python Activity 5: Boolean Expressions and Selection Statements

Python Activity 7: Looping Structures WHILE Loops

Unit 7: Algorithms and Python CS 101, Fall 2018

Name: Partner: Python Activity 9: Looping Structures: FOR Loops

Part 1 Simple Arithmetic

Getting Started Values, Expressions, and Statements CS GMU

CSE 101 Introduction to Computers Development / Tutorial / Lab Environment Setup

Introduction to Python Code Quality

6.S189 Homework 1. What to turn in. Exercise 1.1 Installing Python. Exercise 1.2 Hello, world!

Unit E Step-by-Step: Programming with Python

NESTED IF STATEMENTS AND STRING/INTEGER CONVERSION

Com S 127 Lab 2. For the first two parts of the lab, start up Wing 101 and use the Python shell window to try everything out.

Transitioning Teacher Websites

WebEx. Web Conferencing Tool. Fordham IT

ECS Baruch Lab 3 Spring 2019 Name

Hello, World! An Easy Intro to Python & Programming. Jack Rosenthal

Lab 1: Input, Processing, and Output This lab accompanies Chapter 2 of Starting Out with Programming Logic & Design.

Fundamentals: Expressions and Assignment

Lesson 4: Who Goes There?

CSCI 3300 Assignment 3

Access Forms Masterclass 5 Create Dynamic Titles for Your Forms

Chapter 2 Writing Simple Programs

An Introduction to R 1.1 Getting started

STAT 113: R/RStudio Intro

CIT 590 Homework 5 HTML Resumes

This lab will introduce you to MySQL. Begin by logging into the class web server via SSH Secure Shell Client

nostarch.com/pfk For bulk orders, please contact us at

Visual C# Instructor s Manual Table of Contents

CS 115 Lecture 4. More Python; testing software. Neil Moore

Logical Thinking through Computer Programming

COP 2000 Note Framework Chapter 5 - Repetition Page 1

Intro to Python & Programming. C-START Python PD Workshop

Getting Started. Excerpted from Hello World! Computer Programming for Kids and Other Beginners

T H E I N T E R A C T I V E S H E L L

CSCI 3300 Assignment 3

Text Input and Conditionals

STAT 213: R/RStudio Intro

Student Outcomes. Classwork. Opening Exercise (3 minutes) Example 1 (8 minutes)

CMSC 201 Spring 2017 Homework 4 Lists (and Loops and Strings)

Algorithms and Programming I. Lecture#12 Spring 2015

3-3. When Kenji spun the flag shown at right very quickly about its pole, he noticed that a threedimensional

CS106 Lab 1: Getting started with Python, Linux, and Canopy. A. Using the interpreter as a fancy calculator

Chapter 17. Fundamental Concepts Expressed in JavaScript

Hello World! Computer Programming for Kids and Other Beginners. Chapter 1. by Warren Sande and Carter Sande. Copyright 2009 Manning Publications

Using the Computer for Essays

Python for Analytics. Python Fundamentals RSI Chapters 1 and 2

Python for Non-programmers

CMPT 120 Basics of Python. Summer 2012 Instructor: Hassan Khosravi

Java Programming Fundamentals - Day Instructor: Jason Yoon Website:

The Gaggle ipad App. The Gaggle ipad App functions best when the ipad is kept in landscape mode.

How Do Robots Find Their Way?

An introduction for Calendar Editors (Note: Editors should use Internet Explorer 8, Firefox 3 or higher, or Safari)

CSE 115. Introduction to Computer Science I

SI Networked Computing: Storage, Communication, and Processing, Winter 2009

COSC 123 Computer Creativity. Introduction to Java. Dr. Ramon Lawrence University of British Columbia Okanagan

Tangent line problems

APPM 2460 Matlab Basics

Introduction to programming with Python

In this project, you ll learn how to create your own webpage to tell a story, joke or poem. Think about the story you want to tell.

SIMPLE I/O WITH PYTHON

Loopy stuff: for loops

Lecture 4: Basic I/O

EE457. Homework #7 (Virtual Memory)

A Student s Guide to. writershelp.com. Fall 2010 beta version. Getting started. Finding help. Personalizing and sharing

Lab Assignment 1 Introduction to Programming ICS 31 & CSE 41 Summer Session

Introduction to Programming. Writing Programs Syntax, Logic and Run-time Errors

Lesson 1: Writing Your First JavaScript

Compiling C/C++ programs

WebEx. Web Conferencing Tool. Fordham IT

The current topic: Python. Announcements. Python. Python

Chapter 2, Part I Introduction to C Programming

Fundamentals of Programming Session 4

What is SEO? { Search Engine Optimization }

Chapter 2: Input, Processing, and Output

Flowcharts for Picaxe BASIC

Week 2: Data and Output


Getting Started. Logging In and Out. Adapted from Practical Unix and Programming Hunter College

Pattern Maker Lab. 1 Preliminaries. 1.1 Writing a Python program

What s New in Blackboard 9.1

Over and Over Again GEEN163

NOTE: All references to Python on this exam mean Python 3, so you should answer accordingly.

Shorthand for values: variables

Answer Key Lesson 5: Area Problems

Gaggle ipad App Overview

Quick Start Editors Guide. For Your. MyVFW WebSite

HOW TO EXPORT BUYER NAMES & ADDRESSES FROM PAYPAL TO A CSV FILE

CSI Lab 02. Tuesday, January 21st

Week - 01 Lecture - 04 Downloading and installing Python

Searching Options. Quick Start Guide. With Learn360, there are three different searching options which are displayed in Figures 1, 2, & 3.

Using IDLE for

Using Accommodate. Information for SAS Students at UofG

Once you define a new command, you can try it out by entering the command in IDLE:

age = 23 age = age + 1 data types Integers Floating-point numbers Strings Booleans loosely typed age = In my 20s

CS : Programming for Non-majors, Summer 2007 Programming Project #2: Census Due by 12:00pm (noon) Wednesday June

STUDENT LESSON A7 Simple I/O

Python Class-Lesson1 Instructor: Yao

1 Lecture 5: Advanced Data Structures

Lecture 5. Defining Functions

SIMPLE INPUT and OUTPUT:

Transcription:

Python Activity 2: Input and Variables in Python "How do you input and store data in a Python program?" Learning Objectives Students will be able to: Content: Explain how to input data in Python Explain the meaning and purpose of a variable Determine if a variable name is valid Explain concatenation and the use of "+" Process: Create input statements in Python Create Python code that prompts the user for data and stores it in a variable Create valid and good variable names Prior Knowledge Understanding of flowchart symbols Further Reading https://www.learnpython.org/en/variables_and_types https://www.afterhoursprogramming.com/tutorial/python/variables-py/ https://en.wikibooks.org/wiki/non- Programmer%27s_Tutorial_for_Python_3/Who_Goes_There%3F Information: This activity asks you to execute lines of Python Code. Start the Thonny IDE. In the Shell window you can type individual command lines, or in the editor window you can type a whole program and run it. Model 1: Input in Python Input, one of the four main operations of a computer, is performed using an input statement in Python. The prompt that appears on the screen to tell the user what to enter is included as a string literal in the parentheses of the input statement. Input() and print() are known as functions in python. Flowchart Python Program # Programmer: Monty Python # Date: Sometime in the past # Description: A program that introduces variables name = input("what is your name? ") print("your name is", name) Critical Thinking Questions: 1. Enter and execute the Python program using the editor window in Thonny. To run the program when you are done typing you can either press F5, or click the green arrow. What is printed in the shell window when the Python program is executed?

2. Draw a line between each flowchart symbol and its corresponding Python code. 3. Examine the first line of Python program: name = input("what is your name? ") a. What happens when this line of code is executed? b. What appears in the console window when this line of code is executed? FYI: The words that appear on the screen to tell the user what to enter is known as a prompt. c. Where is the data stored when the user enters something and presses the Enter button? 4. Notice that the word name is in both lines of code. Is the string literal "name" printed when the second line of Python code is executed? What is printed? Model 2: Variables in Python The word name in the Python code is a variable name given to a memory location used to store data. 5. What happens when you execute each of the following lines of Python code? a. name? = input("what is your name?") b. your name = input("what is your name?") c. 1st_name = input("what is your name?") d. from = input("where were you born?") 6. Examine the errors that occurred when executing the lines of code in question 5. Then examine the following lines of valid code. name2 = input("what is your name?") your_name = input("what is your name?") yourname = input("what is your name?") What are the rules for creating a valid variable name?

7. Are the following variable names valid? Are they good names? Why or why not? Variable name price Comments about variable name costoffirstitem Ic firstname Information: Printing Multiple Items and Concatenation You can concatenate two strings literals, two string variables or a string literal and a string variable using the "+" symbol. The strings can be string literals or a variable containing string literals. To print multiple values without being concerned whether they are strings, you can use a "," comma. 8. Predict the output and execute the following lines of code. a. Is the output what you would expect? Why or why not? b. How can you alter the code so that it functions properly? 9. Use the following set of Python statements to answer the questions below. a. State the output for each of line of code. b. What is the difference between the first two print statements? Does the difference affect the output? c. Notice that some statements include a comma (,) between the two literals being printed and some statements use a "+". Do they produce the same output?

d. Explain the purpose of the comma. e. Why does the last print statement crash the program? What would you do to correct it? 10. Execute the following program: a) State what is displayed on the screen when you executed the program. b) The \n is a "string literal escape sequence" in python. What does this do? c) Change the \n to \t and describe what happens to the program output. Application Questions: Use the Thonny IDE to check your work 1. State a good variable name for an employee s ID number. 2. Provide an example of a string literal. 3. Provide an example of a numeric literal. 4. Write a line of Python code that prompts the user for the name of their favorite ice cream and stores it in a valid variable name.

Individual Homework Activity (10pts) Write a Python program that prompts the user for their first name and last name. Assuming that the user s first name is "Monty" and their last name is "Python" the output should be: Be sure your output has the same punctuation as the above output. Your program must contain documentation lines that include your name, the date, a line that states "Py02 Homework question 1" and a description line that indicates what the program is supposed to do. Paste the code to a copy of this end of the word document of this homework assignment and upload to your Google drive, with file name [your last name]_py02_hw Save the program as a python file (ends with.py), with file name [your last name]_py02_program and upload that to the Google Drive. (2 pts) Make 2 annotations on the class page, or any open access webpage dealing with the topic this assignment. Post them to the UALR_IoCT_F2018 group and tag them py02ualrf2018. Remember the tags are case sensitive, and everything is lower case.