Python Problems MTH 151. Texas A&M University. November 8, 2017
|
|
- Arron Wilkins
- 6 years ago
- Views:
Transcription
1 Python Problems MTH 151 Texas A&M University November 8, 2017 Introduction Hello! Welcome to the first problem set for MTH 151 Python. By this point, you should be acquainted with the idea of variables, conditional statements (if-elif), looping, and basic I/O (input/output) in Python. Before continuing on, it is important to understand how Python obtains new features and tools for you to use while programming. Python is a modular language, meaning a lot of its features are contained in tidy little packages called modules. These modules are very similar to MATLAB.m files, except they are even more powerful. Instead of containing only one function (like in MATLAB), each Python module contains many different functions, classes, and cosntants. If we wish to use a particular module that is already installed with Python, we simply use the keyword import. As an example, suppose we wanted to print a random integer to the console, then we could use the following code: 1 import random 2 p r i n t ( random. r a n d i n t ( 0, 100) ) In this case, the module I needed to import was the random module. This module has all kinds of goodies in it for randomly generating numbers. Notice how in order to generate an integer, I had to make a call to random.randint instead of simply randint. This is because whenever we import an entire module, we must make sure to call functions from that module using the module name. The format will always be module.function. This seems annoying though, and thankfully, Python grants us the syntax necessary to avoid this issue. We now can do 1 from random import r andint 2 p r i n t ( r a n d i n t ( 0, 100) ) This enables us to import only the functions and utilities we absolutely need from a particular Python module. Oftentimes, this makes our code run faster and look prettier. I highly recommend you use this for finished code, when it makes sense. Sometimes, however, you may simply need to use all the functions in a particular module, so using import module and grabbing the entire thing may be useful. 1
2 Now, you may be asking yourself, Ryan, this is all well and good, but what if I need functionality outside of the default Python modules? Well, I m glad you asked, stranger reading this. Thankfully, a utility often installed alongside Python can help us in this problem. Suppose you re a game designer, and you need a quick and dirty library for handling input and rendering, called pygame. Python does not come pre-installed with such a library, so we will have to install using this magic utility, pip. This is a commandline tool that is used to update and install modules for Python, but it can only be used if, when installing Python, you chose to add Python to your PATH (Windows OS only, if you re Mac... I recommend googling it). To install this pygame module, you simply need to open up a Windows command line (type cmd into your search bar), and enter the command pip install pygame. On some occasions, it may be necessary to run the command prompt as an administrator, but usually, that doesn t seem to be the case. If everything worked out properly pip will say installed successfully, and you can now go about using import pygame for any Python program you write. Well, that about wraps it up for extending Python functionality, so with that, I wish you the best of luck on these problems! 1 Instructions Each problem should be placed into its own file and named after the particular problem i.e. Problem1a.py. To do this in IDLE, simply open up IDLE, find the File menu at the top left of the shell, select New File, and begin typing in the new window that opens. When you re ready to run your program and see if it works, first save it, then select the Run menu at the top of the text editor window you opened and click Run Module. This will execute your program in the Python shell. Feel free to use any modules that come pre-installed with Python or any you find online, so long as they don t render the problem trivial i.e. Oh, I found a module called Random Password Generator. I think I will use it. Exercise good judgment on these matters, after all, these are problems designed solely for your benefit, not a grade. Problem 1 A.) Computing the hypotenuse of a right triangle This program should ask the user to input two side lengths, then it should output the length of the hypotenuse of the right triangle composed of those two side lengths. (Research will be required to figure out Python s mathematical operators) Below is an example run of the program: 1 P l e a s e e n t e r a s i d e l e n g t h : 3 2 P l e a s e e n t e r another s i d e l e n g t h : 3 The hypotenuse i s o f l e n g t h... 5 B.) Making a good thing better... Now extend your program, so that the user may continue to enter side lengths until they type No. Below is an example: 2
3 1 P l e a s e e n t e r a s i d e l e n g t h : 3 2 P l e a s e e n t e r another s i d e l e n g t h : 3 The hypotenuse i s o f l e n g t h Would you l i k e to f i n d another hypotenuse? Yes 6 P l e a s e e n t e r a s i d e l e n g t h : 7 7 P l e a s e e n t e r another s i d e l e n g t h : 2 8 The hypotenuse i s o f l e n g t h Would you l i k e to f i n d another hypotenuse? No 11 E x i t i n g... C.) Double jeopardy: all or nothing... Now extend your program even further, so that any string starting with n or N will cause the program to exit, and any string starting with y or Y will cause the program to continue. Problem 2 A.) Password generator This program will be a random password generator. First, you must ask the user to input the kind of password they would like with choices weak, medium, or strong. If the user inputs help, then the program should output valid options for them to give the program, what those options mean, and of course, a friendly word of encouragement. A weak password is defined as being between 6 and 8 characters, uses no special symbols i.e.!@#$%^&*+-, and has at most 1 number. A medium password should be 8-10 characters, at least one of which must be a special symbol, at least 2 numbers. A strong password must be characters, contain upper and lower characters, three special symbols, and at least 2 numbers. Finally, if the users input does not match any valid command, then it should output an error message and ask the user to try again. An example is given below, though please do condense my help message in some way: 1 What kind o f password would you l i k e? Help 2 Options are weak, medium, or s t r o n g. A weak password i s d e f i n e d as being between 6 and 8 c h a r a c t e r s, u ses no s p e c i a l symbols i. e.!@#$%ˆ& +, and has at most 1 number. A medium password should be 8 10 c h a r a c t e r s, at l e a s t one o f which must be a s p e c i a l symbol, at l e a s t 2 numbers. A s t r o n g password must be c h a r a c t e r s, contain upper and lower c h a r a c t e r s, t h r e e s p e c i a l symbols, and at l e a s t 2 numbers. 3 What kind o f password would you l i k e? Weak 5 Password : primzq 6 E x i t i n g... Hint: You may find that researching string concatenation is helpful. benefit you to research the "".join() method. Hint: It may also 3
4 B.) A better generator... Now make sure that the locations of all numbers, uppercase letters, lowercase letters, and special symbols are mostly (use your judgment) different each time the user asks for a strong or medium password i.e. 123abc$# and 56def%& would not be considered valid, since all the numbers, letters, and special symbols occur in the same location no matter how many different passwords are generated. An example of two valid password generations would be 123Abc$# and Ef%56&g. Problem 2 adapted from Problem 3 A.) Prime number generator For this program, you will be generating all prime numbers from 1 to n where n is input by the user, putting them into a list, then outputting the list. (You may find the list.append() method helpful) For this program, you are not allowed to use import at all for additional modules, and you may not simply output each prime as you find it i.e. your output should be print(primes) where primes is a list. Sample output is given below. 1 P l e a s e e n t e r the upper bound f o r the primes : 15 2 Primes : [ 1, 2, 3, 5, 7, 11, 1 3 ] 3 E x i t i n g... B.) Prime factorization In a radical departure from previous problems, this doesn t in any way extend the functionality of part a, so get excited! For this problem, you should take a positive integer from the user as input, then output the prime factorization of that number. If the number is prime, then you should output PRIME! :D. If the number is not prime, then you should print out all of its prime factors like this 60: 1 x 2 x 2 x 3 x 5. C.) Guess we ll go back to the extension pattern... In a radical departure from our radical departure, we will extend the functionality of part b. Once again, the user will input a positive integer, but this time, the output should be the prime factorization and all possible factors of that positive integer. In order for this to be a non-trivial problem, you must use the prime factorization you found in part b, to generate all of these factors. Here is a sample output. 1 P l e a s e e n t e r a number to be f a c t o r e d : : 1 x 2 x 2 x 3 x 5 3 Factors : E x i t i n g...
5 While this output is sorted, yours may not necessarily be. We will add that functionality in the next part. D.) And so it ends... Now, repeat part c, but your output should be pairs of numbers that when multiplied together equal the number input by the user. These should be sorted by the first number in the pair and there should be no duplicates in the list. (You may wish to look at tuples or lists of lists and the list.sort() method for this program) Finally, please continue to use the code from parts b and c. This problem becomes trivial if considering it from another angle. As always, sample output is below. 1 P l e a s e e n t e r a number to be f a c t o r e d : : 1 x 2 x 2 x 3 x 5 3 Factors : ( 1, 60) 5 ( 2, 30) 6 ( 3, 20) 7 (, 15) 8 ( 5, 12) 9 ( 6, 10) E x i t i n g... 5
Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming
Intro to Programming Unit 7 Intro to Programming 1 What is Programming? 1. Programming Languages 2. Markup vs. Programming 1. Introduction 2. Print Statement 3. Strings 4. Types and Values 5. Math Externals
More information1. BASICS OF PYTHON. JHU Physics & Astronomy Python Workshop Lecturer: Mubdi Rahman
1. BASICS OF PYTHON JHU Physics & Astronomy Python Workshop 2017 Lecturer: Mubdi Rahman HOW IS THIS WORKSHOP GOING TO WORK? We will be going over all the basics you need to get started and get productive
More informationGetting Started. Excerpted from Hello World! Computer Programming for Kids and Other Beginners
Getting Started Excerpted from Hello World! Computer Programming for Kids and Other Beginners EARLY ACCESS EDITION Warren D. Sande and Carter Sande MEAP Release: May 2008 Softbound print: November 2008
More informationIf Statements, For Loops, Functions
Fundamentals of Programming If Statements, For Loops, Functions Table of Contents Hello World Types of Variables Integers and Floats String Boolean Relational Operators Lists Conditionals If and Else Statements
More informationCSE 101 Introduction to Computers Development / Tutorial / Lab Environment Setup
CSE 101 Introduction to Computers Development / Tutorial / Lab Environment Setup Purpose: The purpose of this lab is to setup software that you will be using throughout the term for learning about Python
More informationcs1114 REVIEW of details test closed laptop period
python details DOES NOT COVER FUNCTIONS!!! This is a sample of some of the things that you are responsible for do not believe that if you know only the things on this test that they will get an A on any
More informationfrom scratch A primer for scientists working with Next-Generation- Sequencing data Chapter 1 Text output and manipulation
from scratch A primer for scientists working with Next-Generation- Sequencing data Chapter 1 Text output and manipulation Chapter 1: text output and manipulation In this unit you will learn how to write
More informationPython Games. Session 1 By Declan Fox
Python Games Session 1 By Declan Fox Rules General Information Wi-Fi Name: CoderDojo Password: coderdojowireless Website: http://cdathenry.wordpress.com/ Plans for this year Command line interface at first
More informationHow To Think Like A Computer Scientist, chapter 3; chapter 6, sections
6.189 Day 3 Today there are no written exercises. Turn in your code tomorrow, stapled together, with your name and the file name in comments at the top as detailed in the Day 1 exercises. Readings How
More informationCSCE 110 Programming I
CSCE 110 Programming I Basics of Python (Part 1): Variables, Expressions, and Input/Output Dr. Tiffani L. Williams Department of Computer Science and Engineering Texas A&M University Spring 2013 Tiffani
More informationIntro. Scheme Basics. scm> 5 5. scm>
Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if
More informationHello World! Computer Programming for Kids and Other Beginners. Chapter 1. by Warren Sande and Carter Sande. Copyright 2009 Manning Publications
Hello World! Computer Programming for Kids and Other Beginners by Warren Sande and Carter Sande Chapter 1 Copyright 2009 Manning Publications brief contents Preface xiii Acknowledgments xix About this
More informationText Input and Conditionals
Text Input and Conditionals Text Input Many programs allow the user to enter information, like a username and password. Python makes taking input from the user seamless with a single line of code: input()
More informationHonors Computer Science Python Mr. Clausen Programs 4A, 4B, 4C, 4D, 4E, 4F
PROGRAM 4A Full Names (25 points) Honors Computer Science Python Mr. Clausen Programs 4A, 4B, 4C, 4D, 4E, 4F This program should ask the user for their full name: first name, a space, middle name, a space,
More informationCSCE 110 Programming I Basics of Python: Variables, Expressions, Input/Output
CSCE 110 Programming I Basics of Python: Variables, Expressions, Input/Output Dr. Tiffani L. Williams Department of Computer Science and Engineering Texas A&M University Spring 2011 Python Python was developed
More informationUnit 7: Algorithms and Python CS 101, Fall 2018
Unit 7: Algorithms and Python CS 101, Fall 2018 Learning Objectives After completing this unit, you should be able to: Identify whether a sequence of steps is an algorithm in the strict sense. Explain
More informationCS 112: Intro to Comp Prog
CS 112: Intro to Comp Prog Importing modules Branching Loops Program Planning Arithmetic Program Lab Assignment #2 Upcoming Assignment #1 Solution CODE: # lab1.py # Student Name: John Noname # Assignment:
More informationExercise 2: Automata Theory
Exercise 2: Automata Theory Formal Methods II, Fall Semester 2013 Distributed: 11.10.2013 Due Date: 25.10.2013 Send your solutions to: tobias.klauser@uzh.ch or deliver them in the class. Finite State Automata
More informationA453 Task 1: Analysis: Problem: Solution:
: Analysis: Problem: The problem I need to solve is that I need to design, code, and test a program that simulates a dice throw of a 4, 6, or 12 sided die and outputs the result before repeating the process
More informationPYTHON YEAR 10 RESOURCE. Practical 01: Printing to the Shell KS3. Integrated Development Environment
Practical 01: Printing to the Shell To program in Python you need the latest version of Python, which is freely available at www.python.org. Your school will have this installed on the computers for you,
More informationPython for Non-programmers
Python for Non-programmers A Gentle Introduction 1 Yann Tambouret Scientific Computing and Visualization Information Services & Technology Boston University 111 Cummington St. yannpaul@bu.edu Winter 2013
More informationMICROPROCESSOR SYSTEMS INTRODUCTION TO PYTHON
MICROPROCESSOR SYSTEMS INTRODUCTION TO PYTHON Table of contents 2 1. Learning Outcomes 2. Introduction 3. The first program: hello world! 4. The second program: hello (your name)! 5. More data types 6.
More informationRecall that strings and tuples are immutable datatypes, while lists are mutable datatypes. What does this mean?
6.189 Day 4 Readings How To Think Like A Computer Scientist, chapters 7 and 8 6.01 Fall 2009 Course Notes page 27-29 ( Lists and Iterations over lists ; List Comprehensions is optional); sections 3.2-3.4
More informationComputer and Programming: Lab 1
01204111 Computer and Programming: Lab 1 Name ID Section Goals To get familiar with Wing IDE and learn common mistakes with programming in Python To practice using Python interactively through Python Shell
More informationASCII Art. Introduction: Python
Python 1 ASCII Art All Code Clubs must be registered. Registered clubs appear on the map at codeclub.org.uk - if your club is not on the map then visit jumpto.cc/18cplpy to find out what to do. Introduction:
More informationPython Unit
Python Unit 1 1.1 1.3 1.1: OPERATORS, EXPRESSIONS, AND VARIABLES 1.2: STRINGS, FUNCTIONS, CASE SENSITIVITY, ETC. 1.3: OUR FIRST TEXT- BASED GAME Python Section 1 Text Book for Python Module Invent Your
More informationYou Need an Interpreter! Comp Spring /28/08 L10 - An Interpreter
You Need an Interpreter! Closing the GAP Thus far, we ve been struggling to speak to computers in their language, maybe its time we spoke to them in ours How high can we rasie the level of discourse? We
More informationS206E Lecture 19, 5/24/2016, Python an overview
S206E057 Spring 2016 Copyright 2016, Chiu-Shui Chan. All Rights Reserved. Global and local variables: differences between the two Global variable is usually declared at the start of the program, their
More informationTable of Contents EVALUATION COPY
Table of Contents Introduction... 1-2 A Brief History of Python... 1-3 Python Versions... 1-4 Installing Python... 1-5 Environment Variables... 1-6 Executing Python from the Command Line... 1-7 IDLE...
More informationCSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch
CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch Purpose: We will take a look at programming this week using a language called Scratch. Scratch is a programming language that was developed
More informationSCRATCH MODULE 3: NUMBER CONVERSIONS
SCRATCH MODULE 3: NUMBER CONVERSIONS INTRODUCTION The purpose of this module is to experiment with user interactions, error checking input, and number conversion algorithms in Scratch. We will be exploring
More informationJython. secondary. memory
2 Jython secondary memory Jython processor Jython (main) memory 3 Jython secondary memory Jython processor foo: if Jython a
More informationGetting started 7. Saving data 23
Contents 1 2 3 4 Getting started 7 Programming code 8 Setting up 10 Exploring IDLE 12 Getting help 14 Saving programs 16 Storing values 18 Adding comments 20 Naming rules 21 Summary 22 Saving data 23 Storing
More informationProgramming Fundamentals and Python
Chapter 2 Programming Fundamentals and Python This chapter provides a non-technical overview of Python and will cover the basic programming knowledge needed for the rest of the chapters in Part 1. It contains
More informationAccess Intermediate
Access 2010 - Intermediate (103-134) Building Access Databases Notes Quick Links Building Databases Pages AC52 AC56 AC91 AC93 Building Access Tables Pages AC59 AC67 Field Types Pages AC54 AC56 AC267 AC270
More informationIntroduction to Programming
Introduction to Programming Python Lab 7: if Statement PythonLab7 lecture slides.ppt 14 November 2017 Ping Brennan (p.brennan@bbk.ac.uk) 1 Getting Started Create a new folder in your disk space with the
More informationSection 0.3 The Order of Operations
Section 0.3 The Contents: Evaluating an Expression Grouping Symbols OPERATIONS The Distributive Property Answers Focus Exercises Let s be reminded of those operations seen thus far in the course: Operation
More informationPython Programming Exercises 3
Python Programming Exercises 3 Notes: These exercises assume that you are comfortable with the contents of the two previous sets of exercises including variables, types, arithmetic expressions, logical
More informationStatistics 13, Lab 1. Getting Started. The Mac. Launching RStudio and loading data
Statistics 13, Lab 1 Getting Started This first lab session is nothing more than an introduction: We will help you navigate the Statistics Department s (all Mac) computing facility and we will get you
More information: Intro Programming for Scientists and Engineers Final Exam
Final Exam Page 1 of 6 600.112: Intro Programming for Scientists and Engineers Final Exam Peter H. Fröhlich phf@cs.jhu.edu December 20, 2012 Time: 40 Minutes Start here: Please fill in the following important
More informationJava Program Structure and Eclipse. Overview. Eclipse Projects and Project Structure. COMP 210: Object-Oriented Programming Lecture Notes 1
COMP 210: Object-Oriented Programming Lecture Notes 1 Java Program Structure and Eclipse Robert Utterback In these notes we talk about the basic structure of Java-based OOP programs and how to setup and
More informationCME 193: Introduction to Scientific Python Lecture 1: Introduction
CME 193: Introduction to Scientific Python Lecture 1: Introduction Nolan Skochdopole stanford.edu/class/cme193 1: Introduction 1-1 Contents Administration Introduction Basics Variables Control statements
More informationCONDITION CONTROLLED LOOPS. Introduction to Programming - Python
CONDITION CONTROLLED LOOPS Introduction to Programming - Python Generating Random Numbers Generating a random integer Sometimes you need your program to generate information that isn t available when you
More informationScripting Languages. Diana Trandabăț
Scripting Languages Diana Trandabăț Master in Computational Linguistics - 1 st year 2017-2018 Today s lecture What is Perl? How to install Perl? How to write Perl progams? How to run a Perl program? perl
More informationDecisions, Decisions. Testing, testing C H A P T E R 7
C H A P T E R 7 In the first few chapters, we saw some of the basic building blocks of a program. We can now make a program with input, processing, and output. We can even make our input and output a little
More informationCOPYRIGHTED MATERIAL. Dipping Your Toe into Python. Part I. Chapter 1: Programming Basics and Strings. Chapter 2: Numbers and Operators
Part I Dipping Your Toe into Python Chapter 1: Programming Basics and Strings Chapter 2: Numbers and Operators Chapter 3: Variables Names for Values COPYRIGHTED MATERIAL 1 Programming Basics and Strings
More informationVISUAL GUIDE to. RX Scripting. for Roulette Xtreme - System Designer 2.0. L J Howell UX Software Ver. 1.0
VISUAL GUIDE to RX Scripting for Roulette Xtreme - System Designer 2.0 L J Howell UX Software 2009 Ver. 1.0 TABLE OF CONTENTS INTRODUCTION...ii What is this book about?... iii How to use this book... iii
More informationMath Day 2 Programming: How to make computers do math for you
Math Day 2 Programming: How to make computers do math for you Matt Coles February 10, 2015 1 Intro to Python (15min) Python is an example of a programming language. There are many programming languages.
More informationChapter 4. Unix Tutorial. Unix Shell
Chapter 4 Unix Tutorial Users and applications interact with hardware through an operating system (OS). Unix is a very basic operating system in that it has just the essentials. Many operating systems,
More informationVariables, expressions and statements
Variables, expressions and statements 2.1. Values and data types A value is one of the fundamental things like a letter or a number that a program manipulates. The values we have seen so far are 2 (the
More informationAPPM 2460 Matlab Basics
APPM 2460 Matlab Basics 1 Introduction In this lab we ll get acquainted with the basics of Matlab. This will be review if you ve done any sort of programming before; the goal here is to get everyone on
More informationTopics. Chapter 5. Equality Operators
Topics Chapter 5 Flow of Control Part 1: Selection Forming Conditions if/ Statements Comparing Floating-Point Numbers Comparing Objects The equals Method String Comparison Methods The Conditional Operator
More informationIntroduction to Python (All the Basic Stuff)
Introduction to Python (All the Basic Stuff) 1 Learning Objectives Python program development Command line, IDEs, file editing Language fundamentals Types & variables Expressions I/O Control flow Functions
More informationT H E I N T E R A C T I V E S H E L L
3 T H E I N T E R A C T I V E S H E L L The Analytical Engine has no pretensions whatever to originate anything. It can do whatever we know how to order it to perform. Ada Lovelace, October 1842 Before
More informationIntroduction to: Computers & Programming: Review prior to 1 st Midterm
Introduction to: Computers & Programming: Review prior to 1 st Midterm Adam Meyers New York University Summary Some Procedural Matters Summary of what you need to Know For the Test and To Go Further in
More informationCMSC 201 Computer Science I for Majors
CMSC 201 Computer Science I for Majors Lecture 02 Intro to Python Syllabus Last Class We Covered Grading scheme Academic Integrity Policy (Collaboration Policy) Getting Help Office hours Programming Mindset
More informationCondition Controlled Loops. Introduction to Programming - Python
Condition Controlled Loops Introduction to Programming - Python Decision Structures Review Programming Challenge: Review Ask the user for a number from 1 to 7. Tell the user which day of the week was selected!
More informationInteractive use. $ python. >>> print 'Hello, world!' Hello, world! >>> 3 $ Ctrl-D
1/58 Interactive use $ python Python 2.7.5 (default, Mar 9 2014, 22:15:05) [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin Type "help", "copyright", "credits" or "license" for more information.
More informationSemester 2, 2018: Lab 1
Semester 2, 2018: Lab 1 S2 2018 Lab 1 This lab has two parts. Part A is intended to help you familiarise yourself with the computing environment found on the CSIT lab computers which you will be using
More informationAlgorithms and Programming I. Lecture#12 Spring 2015
Algorithms and Programming I Lecture#12 Spring 2015 Think Python How to Think Like a Computer Scientist By :Allen Downey Installing Python Follow the instructions on installing Python and IDLE on your
More informationNESTED IF STATEMENTS AND STRING/INTEGER CONVERSION
LESSON 15 NESTED IF STATEMENTS AND STRING/INTEGER CONVERSION OBJECTIVE Learn to work with multiple criteria if statements in decision making programs as well as how to specify strings versus integers in
More informationfile:///users/cerdmann/downloads/ harvard-latest.html
Software Carpentry Bootcamp -- Day 1 http://swcarpentry.github.io/2013-08-23-harvard/ Twitter: @swcarpentry #dst4l Listservs: harvard@lists.software-carpentry.org dst4l@calists.harvard.edu DST4L intro
More informationCPSC 217 Assignment 3
CPSC 217 Assignment 3 Due: Monday November 23, 2015 at 12:00 noon Weight: 7% Sample Solution Length: 135 lines, including some comments (not including the provided code) Individual Work: All assignments
More informationThere are two ways to use the python interpreter: interactive mode and script mode. (a) open a terminal shell (terminal emulator in Applications Menu)
I. INTERACTIVE MODE VERSUS SCRIPT MODE There are two ways to use the python interpreter: interactive mode and script mode. 1. Interactive Mode (a) open a terminal shell (terminal emulator in Applications
More informationdef instructions(response): # Add to instruction_string so that it contains information on # how to play rock-paper-scissors instruction_string = ""
Python Team Project Large development projects are rarely done by one person alone. Instead most developers work in teams. Thus, understanding how to divide up work and collaborate are essential to computer
More informationIs the statement sufficient? If both x and y are odd, is xy odd? 1) xy 2 < 0. Odds & Evens. Positives & Negatives. Answer: Yes, xy is odd
Is the statement sufficient? If both x and y are odd, is xy odd? Is x < 0? 1) xy 2 < 0 Positives & Negatives Answer: Yes, xy is odd Odd numbers can be represented as 2m + 1 or 2n + 1, where m and n are
More informationInteractive use. $ python. >>> print 'Hello, world!' Hello, world! >>> 3 $ Ctrl-D
1/60 Interactive use $ python Python 2.7.5 (default, Mar 9 2014, 22:15:05) [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin Type "help", "copyright", "credits" or "license" for more information.
More informationFormatting: Cleaning Up Data
Formatting: Cleaning Up Data Hello and welcome to our lesson on cleaning up data, which is one of the final ones in this Formatting Module. What we re going to be doing in this lesson is using some of
More informationOther Loop Options EXAMPLE
C++ 14 By EXAMPLE Other Loop Options Now that you have mastered the looping constructs, you should learn some loop-related statements. This chapter teaches the concepts of timing loops, which enable you
More informationnostarch.com/pfk For bulk orders, please contact us at
nostarch.com/pfk For bulk orders, please contact us at sales@nostarch.com. Teacher: Date/Period: Subject: Python Programming Class: Topic: #1 - Getting Started Duration: Up to 50 min. Objectives: Install
More informationA Little Python Part 2
A Little Python Part 2 Introducing Programming with Python Data Structures, Program Control Outline Python and the System Data Structures Lists, Dictionaries Control Flow if, for, while Reminder - Learning
More informationExpress Yourself. The Great Divide
CS 170 Java Programming 1 Numbers Working with Integers and Real Numbers Open Microsoft Word and create a new document Save the file as LastFirst_ic07.doc Replace LastFirst with your actual name Put your
More informationProgramming Project #6: Password File Cracker
CSE231 Spring 2017 Programming Project #6: Password File Cracker (Edits: changed itertools permutations to product either works for these passwords, but product is the correct one. Removed lists and tuples
More informationEncryption à la Mod Name
Rock Around the Clock Part Encryption à la Mod Let s call the integers,, 3,, 5, and the mod 7 encryption numbers and define a new mod 7 multiplication operation, denoted by, in the following manner: a
More informationMy First Command-Line Program
1. Tutorial Overview My First Command-Line Program In this tutorial, you re going to create a very simple command-line application that runs in a window. Unlike a graphical user interface application where
More informationIntro to Python & Programming. C-START Python PD Workshop
Don t just buy a new video game, make one. Don t just download the latest app, help design it. Don t just play on your phone, program it. No one is born a computer scientist, but with a little hard work
More informationChapter 1. Data types. Data types. In this chapter you will: learn about data types. learn about tuples, lists and dictionaries
Chapter 1 Data types In this chapter you will: learn about data types learn about tuples, lists and dictionaries make a magic card trick app. Data types In Python Basics you were introduced to strings
More informationCHAPTER 2: Introduction to Python COMPUTER PROGRAMMING SKILLS
CHAPTER 2: Introduction to Python COMPUTER PROGRAMMING SKILLS 1439-1440 1 Outline 1. Introduction 2. Why Python? 3. Compiler and Interpreter 4. The first program 5. Comments and Docstrings 6. Python Indentations
More informationPython 2.7 will also work for this workshop due to certain language rules, however I prefer working with the most current stable version.
, webmaster@cse-club.com Fall 2014 In this workshop, we will be creating a basic text-based game to learn the basics Python programming language. By the end of this workshop, you will learn: The syntax
More informationStatements 2. a operator= b a = a operator b
Statements 2 Outline Note: i=i+1 is a valid statement. Don t confuse it with an equation i==i+1 which is always false for normal numbers. The statement i=i+1 is a very common idiom: it just increments
More informationHello! ios Development
SAMPLE CHAPTER Hello! ios Development by Lou Franco Eitan Mendelowitz Chapter 1 Copyright 2013 Manning Publications Brief contents PART 1 HELLO! IPHONE 1 1 Hello! iphone 3 2 Thinking like an iphone developer
More informationPlay with Python: An intro to Data Science
Play with Python: An intro to Data Science Ignacio Larrú Instituto de Empresa Who am I? Passionate about Technology From Iphone apps to algorithmic programming I love innovative technology Former Entrepreneur:
More informationPYTHON FOR KIDS A Pl ayfu l I ntrodu ctio n to Prog r am m i ng J a s o n R. B r i g g s
PYTHON FO R K I D S A P l ay f u l I n t r o d u c t i o n to P r o g r a m m i n g Jason R. Briggs Index Symbols and Numbers + (addition operator), 17 \ (backslash) to separate lines of code, 235 in strings,
More informationCongruence Arithmetic
Module 4 Congruence Arithmetic Popper 4 Introduction to what is like Modulus choices Partitions by modulus Mod 5 Mod 7 Mod 30 Modular Arithmetic Addition Subtraction Multiplication INTEGERS! Mod 12 Cayley
More informationProgramming for Non-Programmers
Programming for Non-Programmers Python Chapter 2 Source: Dilbert Agenda 6:00pm Lesson Begins 6:15pm First Pillow example up and running 6:30pm First class built 6:45pm Food & Challenge Problem 7:15pm Wrap
More informationSchoolMessenger App. User Guide - Web. 100 Enterprise Way, Suite A-300. Scotts Valley, CA
COMMUNICATE SchoolMessenger App User Guide - Web West Corporation 100 Enterprise Way, Suite A-300 Scotts Valley, CA 95066 888-527-5225 www.schoolmessenger.com Table of Contents Welcome!... 3 There are
More informationThe current topic: Python. Announcements. Python. Python
The current topic: Python Announcements! Introduction! reasons for studying languages! language classifications! simple syntax specification Object-oriented programming: Python Types and values Syntax
More informationMEIN 50010: Python Introduction
: Python Fabian Sievers Higgins Lab, Conway Institute University College Dublin Wednesday, 2017-10-04 Outline Goals Teach basic programming concepts Apply these concepts using Python Use Python Packages
More informationExcerpt from "Art of Problem Solving Volume 1: the Basics" 2014 AoPS Inc.
Chapter 5 Using the Integers In spite of their being a rather restricted class of numbers, the integers have a lot of interesting properties and uses. Math which involves the properties of integers is
More informationAMS 200: Working on Linux/Unix Machines
AMS 200, Oct 20, 2014 AMS 200: Working on Linux/Unix Machines Profs. Nic Brummell (brummell@soe.ucsc.edu) & Dongwook Lee (dlee79@ucsc.edu) Department of Applied Mathematics and Statistics University of
More informationENGR 101 Engineering Design Workshop
ENGR 101 Engineering Design Workshop Lecture 2: Variables, Statements/Expressions, if-else Edgardo Molina City College of New York Literals, Variables, Data Types, Statements and Expressions Python as
More information1.2 Adding Integers. Contents: Numbers on the Number Lines Adding Signed Numbers on the Number Line
1.2 Adding Integers Contents: Numbers on the Number Lines Adding Signed Numbers on the Number Line Finding Sums Mentally The Commutative Property Finding Sums using And Patterns and Rules of Adding Signed
More informationLOOPS. Repetition using the while statement
1 LOOPS Loops are an extremely useful feature in any programming language. They allow you to direct the computer to execute certain statements more than once. In Python, there are two kinds of loops: while
More informationIntroduction to Scientific Python, CME 193 Jan. 9, web.stanford.edu/~ermartin/teaching/cme193-winter15
1 LECTURE 1: INTRO Introduction to Scientific Python, CME 193 Jan. 9, 2014 web.stanford.edu/~ermartin/teaching/cme193-winter15 Eileen Martin Some slides are from Sven Schmit s Fall 14 slides 2 Course Details
More information3x - 5 = 22 4x - 12 = 2x - 9
3. Algebra Solving Equations ax + b = cx + d Algebra is like one big number guessing game. I m thinking of a number. If you multiply it by 2 and add 5, you get 21. 2x + 5 = 21 For a long time in Algebra
More informationAn Interesting Way to Combine Numbers
An Interesting Way to Combine Numbers Joshua Zucker and Tom Davis October 12, 2016 Abstract This exercise can be used for middle school students and older. The original problem seems almost impossibly
More information6.149 Checkoff 2. What to complete. Recall: Creating a file and running a program in IDLE.
6.149 Checkoff 2 http://web.mit.edu/6.149/www/materials.html What to complete Due: Wednesday, January 14, 2015 @ 5 p.m. 1. checkoff2 user input.py, which will contain your code for 2.1 - User input 2.
More informationThe name of our class will be Yo. Type that in where it says Class Name. Don t hit the OK button yet.
Mr G s Java Jive #2: Yo! Our First Program With this handout you ll write your first program, which we ll call Yo. Programs, Classes, and Objects, Oh My! People regularly refer to Java as a language that
More informationWhat you get When you install Python for your computer, you get a number of features:
Lab 1 CS161 Exercise 1: In the beginning Why Python? Python is a programming language that was first conceived by Guido van Rossum in the late 1980 s and in 1990. While there are a number of programming
More information4th Pui Ching Invitational Mathematics Competition. Heat Event (Secondary 2)
4th Pui Ching Invitational Mathematics Competition Heat Event (Secondary 2) 1 15 Time allowed: 1 hour 15 minutes Instructions to Contestants: 1. 20 100 There are 20 questions in this paper and the total
More information