CS 105 Lab As a review of what we did last week a. What are two ways in which the Python shell is useful to us?
|
|
- Julie Eaton
- 5 years ago
- Views:
Transcription
1 1 CS 105 Lab 3 The purpose of this lab is to practice the techniques of making choices and looping. Before you begin, please be sure that you understand the following concepts that we went over in class: How to use: if, elif, else The difference between a while loop and a for loop Error checking of input Examples we did in class such as the prime number program, and getting the computer to count. If you are unsure about any of the above, please don t hesitate to ask for help. On your USB drive or computer account, please create a new folder called lab03. All the files you create will go into this folder. Start the Python system like you did in the previous lab. You will need two windows: the shell, and the editor. 1. As a review of what we did last week a. What are two ways in which the Python shell is useful to us? b. Why does a program need comments? c. Give an example Python statement that will read a real number as input from the user. Hint: you need to use two built-in functions to accomplish this. Part 1: Fahrenheit Celsius converter Let s write a program that allows a user to convert between Fahrenheit and Celsius temperatures. This program will have two inputs. First, we want the program to let the user choose which way to convert, either Fahrenheit-to-Celsius or Celsius-to-Fahrenheit. The user will specify this choice by entering either the letter F or C, respectively. The second input will be the temperature. Then, the program can perform the appropriate conversion and output the result. 2. What are the types of these two inputs? Specify which one is which.
2 2 Here is the code for the program. Please type it in, and save the program as convert.py. Please note that there are some details that you need to fill in, such as the appropriate condition to use with the ifstatement, and the two conversion formulas. In your if-statement, you will need to use quotes around the letter C or F so that Python does not think that you are using this letter as a variable. Another hint: F = (9/5) C You can solve for C to determine the other formula. # convert.py Convert between Fahrenheit and Celsius # Purpose: to practice the if-else statement. # input print("would you like to convert from F to C or from C to F?") print("enter F if you want to convert a Fahrenheit temperature, or") print("enter C to enter a Celsius temperature.") choice = input("enter your choice (F/C): ") # Perform calculation based on whether F or C was entered. if : f = input("enter the Fahrenheit temperature: ") # insert Celsius formula... c = print("the equivalent Celsius temperature is ", c) else: c = input("enter the Celsius temperature: ") # insert Fahrenheit formula f = print("the equivalent Fahrenheit temperature is ", f) print("thank you for using my temperature conversion program.") 3. Oops! There was an error in the program I gave you. How did you fix it? 4. Run the program both ways, to check that both formulas you entered work correctly. Ask your program for these conversions: 14 Fahrenheit = in Celsius 25 Celsius = in Fahrenheit
3 3 5. How would the program behave differently if the last statement in the program were indented? In other words, when running the program, how could we tell that something is abnormal? Part 2: Adding error checking As we saw in class, there is a straightforward way to get a program to check the validity of the user s input. If the input is invalid, we can print an appropriate error message and allow the user to try again without having to quit the program and start over. For example, here is how we could check to make sure that the user enters a positive number: needinput = True while needinput: n = int(input("enter a positive integer: ")) if n > 0: needinput = False else: print("sorry, input is invalid. Please try again.") 6. What data type is the value contained in needinput? Modify convert.py so that it performs error checking on the first input. It must be the capital letter F or the capital letter C. If it is any other character, this would be considered invalid. Be sure to use quotes around the F and the C, so that the computer does not think that these are variable names. Also note that some of the code that you wrote earlier now needs to be indented. 7. Write down the if-statement s condition that helps you perform the error checking.
4 4 Part 3: Practice with multiple-choice if-statement Let s write a simple program that works with days of the week. Create a new source file called monday.py. The purpose of this program is to ask the user for a positive integer n, and then output what day of the week it is n days after a Monday. For example, if the user enters 27, the answer should be Sunday. The general format of the program is as follows. I ll describe the structure in English: First, we ask the user to enter a positive integer, and put this answer in a variable called n. Second, we perform the calculation n % 7 and put the result back into n. 8. What are the smallest and largest possible values of n after we perform this calculation? Third, we create a new variable called day, which will contain a string. This string will be the name of the day of the week that is n days after Monday. Finally, we print a sentence telling the user what the value of day is. To start you off, you may copy the following code into your monday.py file. There are two things you need to add to this program. First, you need to make the appropriate assignment statement that modifies n. And second, you need to add the additional cases in the if-statement to handle all possible days of the week. # monday.py What day of the week is it n days after a Monday? # input n = int(input("enter a positive integer: ")) # mod n by 7 and make this the new value of n # You need to enter this assignment statement here: # Create a new variable called day, and set it to a string # such as "Monday", "Tuesday", etc. depending on the value of n. # Because there are several choices, we will make use of the # Python words if, elif, and else. if n == 0: day = "Monday" # Insert the remaining cases here... # Ready for output: print(n, " days after Monday will be ", day)
5 5 9. When you are ready to run your program, test it a few times with various input. Try these: 12 days after a Monday is 100 days after a Monday is 365 days after a Monday is One billion days after a Monday is 10. How can you tell if your output (e.g. that you just wrote down above) is correct? 11. If the user entered the number 1 as input, our output will begin as follows 1 days after Monday This is not grammatically correct. Show how you would use an if-statement to handle this special case of n equals 1. In this case we want to print the word day instead of days. 12. When you run the program with n equals 12, the program responds by saying 5 days after Monday The reason why the 12 became 5 is that we performed a mod operation on n. Let s modify the program so that it also retains the original value of n. Explain how you would do this: Make the necessary modification to your program, and show it to the instructor or lab aide.
6 6 Part 4: Practice with a while loop Let s use a while loop to help us add a series of numbers of this form: n The format of this program will be simple. First, the program will ask the user for a positive integer n. Next, the program will have a while loop that counts from 1 to n. This should sound familiar because we did something similar to this in class. However, now, instead of simply counting, we want to perform a cumulative addition. So, we are going to need another variable called sum or total. Create a new source file called sum.py. You may use the following code to start you off. Some details have been left out, such as the initial values of count and sum, as well as the assignment statement for sum inside the while loop. # sum.py Find the sum of the numbers from 1 to n, where n # is specified by the user. # input n = int(input("please enter a positive integer: ")) count = sum = while count <= n: # You need to insert an assignment statement to modify sum. # output print("the sum from 1 to ", n, " is ", sum) 13. Once you are finished entering in your program, run it several times on various cases. Write down these results. If n = 3, the sum is If n = 10, the sum is If n = 1414, the sum is If n = 5, the sum is
7 7 Part 5: Practice with a for loop It turns out that Python has two kinds of loops: while loops and for loops. Copy your sum.py program into a new version called sum2.py. We will make some changes to this program. First, replace the while loop with a for loop. In order to accomplish this, you will need to use the range function. 14. Let s review. If we call the range function with the parameters 1 and 5 like this: range (1, 5), what is the resulting list of numbers? Next, we will perform one more modification to sum2.py. Rather than summing just the positive integers from 1 to n, let s sum the squares of these numbers. In other words, your program should calculate: n 2. To accomplish this change, you need to modify the assignment to sum inside the for-loop. Also, please change the output statement so that it reads The sum of the squares from 1 to 15. When you are ready, run your program on several different input values for n. And write down your results of these tests: If n = 3, the sum is If n = 175, the sum is If n = 5, the sum is 16. Write down the while loop you have in sum.py, and beside it, write down the for-loop you have in sum2.py. Which type of loop do you prefer, and why? 17. Explain how you would modify the program so that it prints the value of sum each time we add the next perfect square. Show the instructor or lab aide your program s output.
8 8 Part 6: The break statement The purpose of the break statement is to allow a program to abandon the remaining iterations of a loop. Let s use the break statement in one of the earlier example programs we saw in class. Specifically, it will be the program that determined if a number is prime. Create a new Python source file called prime.py. From your class notes, copy the prime number program into prime.py. 18. Run the program to make sure that it works correctly. What input value did you test to see that your program could tell if a number is a. Prime? b. Not prime? The idea behind this program is that we are counting divisors. If the number of divisors is 2, then the input number is prime. But in general, this can be inefficient. During the loop, if we have already encountered 3 or more divisors, what is the point in continuing? Modify your program so that it will break from the loop if the number of divisors found is 3 or more. 19. Have the instructor or lab aide check your work for this part. 20. What is an example of an input value for which your program will now run much faster thanks to having a break statement? What made you choose this number? 21. Suggest another way that this program can be improved or enhanced.
LOOPS. 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 informationChapter 2 Writing Simple Programs
Chapter 2 Writing Simple Programs Charles Severance Textbook: Python Programming: An Introduction to Computer Science, John Zelle (www.si182.com) Software Development Process Figure out the problem - for
More informationCMSC201 Computer Science I for Majors
CMSC201 Computer Science I for Majors Lecture 06 Decision Structures Prof. Katherine Gibson Prof. Jeremy Dixon Based on concepts from: https://blog.udemy.com/python-if-else/ Last Class We Covered Just
More informationCS 115 Exam 1, Fall 2015 Thu. 09/24/2015
CS 115 Exam 1, Fall 2015 Thu. 09/24/2015 Name: Section: Rules and Hints You may use one handwritten 8.5 11 cheat sheet (front and back). This is the only additional resource you may consult during this
More informationIntroduction to Computer Programming for Non-Majors
Introduction to Computer Programming for Non-Majors CSC 2301, Fall 2016 Chapter 2 Instructor: Long Ma The Department of Computer Science Review Install and test python Basic concept of computers Test simple
More informationDecision Structures CSC1310. Python Programming, 2/e 1
Decision Structures CSC1310 Python Programming, 2/e 1 Simple Decisions Decision structures, which are statements that allow a program to execute different sequences of instructions for different cases,
More informationCMSC 201 Fall 2016 Lab 09 Advanced Debugging
CMSC 201 Fall 2016 Lab 09 Advanced Debugging Assignment: Lab 09 Advanced Debugging Due Date: During discussion Value: 10 points Part 1: Introduction to Errors Throughout this semester, we have been working
More informationFundamentals of Programming (Python) Getting Started with Programming
Fundamentals of Programming (Python) Getting Started with Programming Ali Taheri Sharif University of Technology Some slides have been adapted from Python Programming: An Introduction to Computer Science
More informationFlow Control: Branches and loops
Flow Control: Branches and loops In this context flow control refers to controlling the flow of the execution of your program that is, which instructions will get carried out and in what order. In the
More informationIntroduction to Computer Programming for Non-Majors
Introduction to Computer Programming for Non-Majors CSC 2301, Fall 2016 Chapter 7 Part 1 Instructor: Long Ma The Department of Computer Science Objectives---Decision Structures 2 To understand the programming
More informationPython Programming: An Introduction to Computer Science
Python Programming: An Introduction to Computer Science Chapter 7 Decision Structures Python Programming, 2/e 1 Objectives æ To understand the programming pattern simple decision and its implementation
More informationCS 1110, LAB 10: ASSERTIONS AND WHILE-LOOPS 1. Preliminaries
CS 0, LAB 0: ASSERTIONS AND WHILE-LOOPS http://www.cs.cornell.edu/courses/cs0/20sp/labs/lab0.pdf. Preliminaries This lab gives you practice with writing loops using invariant-based reasoning. Invariants
More informationSI Networked Computing: Storage, Communication, and Processing, Winter 2009
University of Michigan Deep Blue deepblue.lib.umich.edu 2009-01 SI 502 - Networked Computing: Storage, Communication, and Processing, Winter 2009 Severance, Charles Severance, C. (2008, December 19). Networked
More informationWorlframalpha.com Facebook Report
Worlframalpha.com Facebook Report For Tuesday: have read up through chapter 2 Next week will start chapter 3 New lab today: Simple Programs Integer division? o 1//3 o - 1//3 Range start at something other
More informationGetting Started with Python
Fundamentals of Programming (Python) Getting Started with Python Sina Sajadmanesh Sharif University of Technology Some slides have been adapted from Python Programming: An Introduction to Computer Science
More informationIntro 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 informationProgramming. We will be introducing various new elements of Python and using them to solve increasingly interesting and complex problems.
Plan for the rest of the semester: Programming We will be introducing various new elements of Python and using them to solve increasingly interesting and complex problems. We saw earlier that computers
More informationLecture 5. Defining Functions
Lecture 5 Defining Functions Announcements for this Lecture Last Call Quiz: About the Course Take it by tomorrow Also remember the survey Readings Sections 3.5 3.3 today Also 6.-6.4 See online readings
More informationPython lab session 1
Python lab session 1 Dr Ben Dudson, Department of Physics, University of York 28th January 2011 Python labs Before we can start using Python, first make sure: ˆ You can log into a computer using your username
More informationLecture Writing Programs. Richard E Sarkis CSC 161: The Art of Programming
Lecture Writing Programs Richard E Sarkis CSC 161: The Art of Programming Class Administrivia Agenda To be able to understand and write Python statements to output information to the screen To assign values
More informationModule Contact: Dr Pierre Chardaire, CMP Copyright of the University of East Anglia Version 1
UNIVERSITY OF EAST ANGLIA School of Computing Sciences Main Series UG Examination 2015/16 INTRODUCTORY PROGRAMMING CMP-0005B Time allowed: 2 hours. Answer BOTH questions from section A and ONE question
More informationCS 150 Lab 3 Arithmetic and the Debugger. Lab 3.0 We are going to begin using the Visual Studio 2017 debugger to aid with debugging programs.
CS 150 Lab 3 Arithmetic and the Debugger The main objective of today s lab is to use some basic mathematics to solve a few real world problems. In doing so, you are to begin getting accustomed to using
More informationIntroduction to Computer Programming for Non-Majors
Introduction to Computer Programming for Non-Majors CSC 2301, Fall 2015 Chapter 7 Part 1 The Department of Computer Science Objectives 2 To understand the programming pattern simple decision and its implementation
More informationAlgorithms and Data Structures
Algorithms and Data Structures 4. Łódź 2018 Exercise Harmonic Sum - Type in the program code - Save it as harmonic.py - Run the script using IPython Wikipedia - This program uses the for loop, the range()
More information3.4. FOR-LOOPS 65. for <v a r i a b l e > in < sequence >:
3.4. FOR-LOOPS 65 3.4 For-loops In the previous section we looked at while-loops, Python s basic looping structure. There is a second loop construct in Python called a for-loop. This is more specialized.
More information1. What is the minimum number of bits needed to store a single piece of data representing: a. An integer between 0 and 100?
1 CS 105 Review Questions Most of these questions appeared on past exams. 1. What is the minimum number of bits needed to store a single piece of data representing: a. An integer between 0 and 100? b.
More informationIteration Part 1. Motivation for iteration. How does a for loop work? Execution model of a for loop. What is Iteration?
Iteration Part 1 Motivation for iteration Display time until no more time left Iteration is a problemsolving strategy found in many situations. Keep coding until all test cases passed CS111 Computer Programming
More informationPython Programming: An Introduction to Computer Science
Python Programming: An Introduction to Computer Science Chapter 7 Decision Structures Python Programming, 2/e 1 Objectives n To understand the programming pattern simple decision and its implementation
More informationCMPT 120 Control Structures in Python. Summer 2012 Instructor: Hassan Khosravi
CMPT 120 Control Structures in Python Summer 2012 Instructor: Hassan Khosravi The If statement The most common way to make decisions in Python is by using the if statement. The if statement allows you
More informationUnit E Step-by-Step: Programming with Python
Unit E Step-by-Step: Programming with Python Computer Concepts 2016 ENHANCED EDITION 1 Unit Contents Section A: Hello World! Python Style Section B: The Wacky Word Game Section C: Build Your Own Calculator
More information(Python) Chapter 3: Repetition
(Python) Chapter 3: Repetition 3.1 while loop Motivation Using our current set of tools, repeating a simple statement many times is tedious. The only item we can currently repeat easily is printing the
More informationComputer Science 217
Computer Science 17 Midterm Exam March 5, 014 Exam Number 1 First Name: Last Name: ID: Class Time (Circle One): 1:00pm :00pm Instructions: Neatly print your names and ID number in the spaces provided above.
More informationLecture 3. Input, Output and Data Types
Lecture 3 Input, Output and Data Types Goals for today Variable Types Integers, Floating-Point, Strings, Booleans Conversion between types Operations on types Input/Output Some ways of getting input, and
More informationAP Computer Science Unit 3. Programs
AP Computer Science Unit 3. Programs For most of these programs I m asking that you to limit what you print to the screen. This will help me in quickly running some tests on your code once you submit them
More informationPython Programming: An Introduction to Computer Science
Python Programming: An Introduction to Computer Science Chapter 2 Python Programming, 2/e 1 Objectives n To be able to understand and write Python statements to output information to the screen, assign
More informationCITS 4406 Problem Solving & Programming
CITS 4406 Problem Solving & Programming Tim French Lecture 02 The Software Development Process (These slides are based on John Zelle s powerpoint slides for lectures accompanied with the text book) Objectives
More informationVariable and Data Type I
Islamic University Of Gaza Faculty of Engineering Computer Engineering Department Lab 2 Variable and Data Type I Eng. Ibraheem Lubbad September 24, 2016 Variable is reserved a location in memory to store
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 informationQuiz. Introduction: Python. In this project, you ll make a quiz game to challenge your friends. Activity Checklist.
Python 1 Quiz 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 Activity 7: Looping Structures WHILE Loops
Python Activity 7: Looping Structures WHILE Loops How can I get my code to repeat output or processes? Learning Objectives Students will be able to: Content: Explain the three parts of a loop Explain the
More information1 Truth. 2 Conditional Statements. Expressions That Can Evaluate to Boolean Values. Williams College Lecture 4 Brent Heeringa, Bill Jannen
1 Truth Last lecture we learned about the int, float, and string types. Another very important object type in Python is the boolean type. The two reserved keywords True and False are values with type boolean.
More informationComputer Science Lab Exercise 2
osc 127 Lab 2 1 of 10 Computer Science 127 - Lab Exercise 2 Excel User-Defined Functions - Repetition Statements (pdf) During this lab you will review and practice the concepts that you learned last week
More informationCS 1110: Introduction to Computing Using Python Loop Invariants
CS 1110: Introduction to Computing Using Python Lecture 21 Loop Invariants [Andersen, Gries, Lee, Marschner, Van Loan, White] Announcements Prelim 2 conflicts due by midnight tonight Lab 11 is out Due
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 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 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 informationComputer Science 217
Computer Science 217 Midterm Exam Fall 2012 November 1, 2012 Name: ID: Class Time (Circle One): 1:00pm 3:00pm Instructions: Neatly print your name and ID number in the spaces provided above. Pick the best
More informationCOMP-202: Foundations of Programming. Lecture 8: for Loops, Nested Loops and Arrays Jackie Cheung, Winter 2016
COMP-202: Foundations of Programming Lecture 8: for Loops, Nested Loops and Arrays Jackie Cheung, Winter 2016 Review What is the difference between a while loop and an if statement? What is an off-by-one
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 informationAPPM 2460: Week Three For, While and If s
APPM 2460: Week Three For, While and If s 1 Introduction Today we will learn a little more about programming. This time we will learn how to use for loops, while loops and if statements. 2 The For Loop
More information1 Information system An information system is the combination of technology(computers) and people that enable an organization to collect data, store them, and transform them into information Data Data
More informationName & Recitation Section:
Name & Recitation Section: Due Wednesday, Jan 5 at 2:10 PM in 34-101. Please print out your code files (homework 1.py, rps.py, loops.py, and any code you wrote for optional problems), staple them to the
More informationPython Programming: An Introduction to Computer Science
Python Programming: An Introduction to Computer Science Chapter 2 Writing Simple Programs Python Programming, 3/e 1 Objectives n To know the steps in an orderly software development process. n To understand
More informationIntroduction to Computer Programming for Non-Majors
Introduction to Computer Programming for Non-Majors CSC 2301, Fall 2014 Chapter 2 The Department of Computer Science Chapter 2 Elements of Programs-Objectives To be able to understand and write Python
More informationPython for Informatics
Python for Informatics Exploring Information Version 0.0.6 Charles Severance Chapter 3 Conditional execution 3.1 Boolean expressions A boolean expression is an expression that is either true or false.
More informationCpSc 1011 Lab 4 Formatting and Flow Control Windchill Temps
CpSc 1011 Lab 4 Formatting and Flow Control Windchill Temps Overview By the end of the lab, you will be able to: use fscanf() to accept inputs from the user and use fprint() for print statements to the
More informationIntroduction to Programming
Introduction to Programming Python Lab 8: Loops PythonLab8 lecture slides.ppt 20 November 2018 Ping Brennan (p.brennan@bbk.ac.uk) 1 Getting Started Create a new folder in your disk space with the name
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 informationComputer Programming, I. Laboratory Manual. Experiment #2. Elementary Programming
Think Twice Code Once The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2005 Khaleel I. Shaheen Computer Programming, I Laboratory Manual Experiment #2
More informationSCHEME 8. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. March 23, 2017
SCHEME 8 COMPUTER SCIENCE 61A March 2, 2017 1 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,
More informationCISC 181 Lab 2 (100 pts) Due: March 4 at midnight (This is a two-week lab)
CISC 181 Lab 2 (100 pts) Due: March 4 at midnight (This is a two-week lab) This lab should be done individually. Labs are to be turned in via Sakai by midnight on Tuesday, March 4 (the midnight between
More informationIntroduction to Java Applications
2 Introduction to Java Applications OBJECTIVES In this chapter you will learn: To write simple Java applications. To use input and output statements. Java s primitive types. Basic memory concepts. To use
More informationThe while Loop 4/6/16 4
Chapter 4: Loops Chapter Goals To implement while and for loops To hand-trace the execution of a program To become familiar with common loop algorithms To understand nested loops To implement programs
More informationProgramming with Python
Programming with Python Dr Ben Dudson Department of Physics, University of York 21st January 2011 http://www-users.york.ac.uk/ bd512/teaching.shtml Dr Ben Dudson Introduction to Programming - Lecture 2
More informationTypes, lists & functions
Week 2 Types, lists & functions Data types If you want to write a program that allows the user to input something, you can use the command input: name = input (" What is your name? ") print (" Hello "+
More informationShell Script Programs with If Then Else Statements
Shell Script Programs with If Then Else Statements June 3, 2010 Copyright 2010 by World Class CAD, LLC. All Rights Reserved. Adding Comments When we want to place a comment in a Shell Script, we type the
More informationPart 1. Creating an Array of Controls or Indicators
NAME EET 2259 Lab 9 Arrays OBJECTIVES -Write LabVIEW programs using arrays. Part 1. Creating an Array of Controls or Indicators Here are the steps you follow to create an array of indicators or controls
More informationStep by step set of instructions to accomplish a task or solve a problem
Step by step set of instructions to accomplish a task or solve a problem Algorithm to sum a list of numbers: Start a Sum at 0 For each number in the list: Add the current sum to the next number Make the
More informationCISC 181 Lab 2 (100 pts) Due: March 7 at midnight (This is a two-week lab)
CISC 181 Lab 2 (100 pts) Due: March 7 at midnight (This is a two-week lab) This lab may be done individually or with a partner. Working with a partner DOES NOT mean, you do the evens, and I ll do the odds.
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 informationSenior Math Circles Cryptography and Number Theory Week 1
Senior Math Circles Cryptography and Number Theory Week 1 Dale Brydon Feb. 2, 2014 1 One-Time Pads Cryptography deals with the problem of encoding a message in such a way that only the intended recipient
More informationCondition Controlled Loops. Introduction to Programming - Python
+ Condition Controlled Loops Introduction to Programming - Python + Repetition Structures n Programmers commonly find that they need to write code that performs the same task over and over again + Example:
More informationCS1110 Lab 6 (Mar 17-18, 2015)
CS1110 Lab 6 (Mar 17-18, 2015) First Name: Last Name: NetID: The lab assignments are very important and you must have a CS 1110 course consultant tell CMS that you did the work. (Correctness does not matter.)
More informationCS Lab 11. Today's Objectives. Prime Number Generation Implement Diffie-Hellman Key Exchange Implement RSA Encryption
CS 105 - Lab 11 Today's Objectives Prime Number Generation Implement Dfie-Hellman Key Exchange Implement RSA Encryption Part 1: Dfie-Hellman Key Exchange In class you learned about the Dfie-Hellman-Merkle
More informationMath 1: Solutions to Written Homework 1 Due Friday, October 3, 2008
Instructions: You are encouraged to work out solutions to these problems in groups! Discuss the problems with your classmates, the tutors and/or the instructors. After working doing so, please write up
More informationIntroduction to Computer Programming for Non-Majors
Introduction to Computer Programming for Non-Majors CSC 2301, Fall 2016 Chapter 3 Instructor: Long Ma The Department of Computer Science Review of Chapter 2 Stages of creating a program: Analyze the problem
More informationControl Flow: Loop Statements
Control Flow: Loop Statements A loop repeatedly executes a of sub-statements, called the loop body. Python provides two kinds of loop statements: a for-loop and a while-loop. This exercise gives you practice
More informationUsing IDLE for
Using IDLE for 15-110 Step 1: Installing Python Download and install Python using the Resources page of the 15-110 website. Be sure to install version 3.3.2 and the correct version depending on whether
More informationCSCE 110 Programming I Basics of Python: Lists, Tuples, and Functions
CSCE 110 Programming I Basics of Python: Lists, Tuples, and Functions Dr. Tiffani L. Williams Department of Computer Science and Engineering Texas A&M University Fall 2011 Lists Ordered collection of data.
More informationSCHEME 7. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. October 29, 2015
SCHEME 7 COMPUTER SCIENCE 61A October 29, 2015 1 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,
More informationTOPIC 2 INTRODUCTION TO JAVA AND DR JAVA
1 TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson, and instructor materials prepared
More informationMidterm Exam 2B Answer key
Midterm Exam 2B Answer key 15110 Principles of Computing Fall 2015 April 6, 2015 Name: Andrew ID: Lab section: Instructions Answer each question neatly in the space provided. There are 6 questions totaling
More informationWhat is Iteration? CMPT-101. Recursion. Understanding Recursion. The Function Header and Documentation. Recursively Adding Numbers
What is Iteration? CMPT-101 Week 6 Iteration, Iteration, Iteration, Iteration, Iteration, Iteration,... To iterate means to do the same thing again and again and again and again... There are two primary
More informationCS1 Lecture 3 Jan. 18, 2019
CS1 Lecture 3 Jan. 18, 2019 Office hours for Prof. Cremer and for TAs have been posted. Locations will change check class website regularly First homework assignment will be available Monday evening, due
More informationIntroduction to Programming
Introduction to Programming Python Lab 5: Strings and Output PythonLab5 lecture slides.ppt 30 October 2018 Ping Brennan (p.brennan@bbk.ac.uk) 1 Getting Started Create a new folder in your disk space with
More informationCSci 1113, Fall 2015 Lab Exercise 4 (Week 5): Write Your Own Functions. User Defined Functions
CSci 1113, Fall 2015 Lab Exercise 4 (Week 5): Write Your Own Functions User Defined Functions In previous labs, you've encountered useful functions, such as sqrt() and pow(), that were created by other
More informationVariable and Data Type I
The Islamic University of Gaza Faculty of Engineering Dept. of Computer Engineering Intro. To Computers (LNGG 1003) Lab 2 Variable and Data Type I Eng. Ibraheem Lubbad February 18, 2017 Variable is reserved
More informationPython 2 Conditionals and loops Matthew Egbert CS111
Python 2 Conditionals and loops Matthew Egbert CS111 Yesterday's Lecture Input and Output user_input_as_str = input('prompt: ') print('hello. You entered: '+ user_input_as_str) Comments # everything to
More informationINDIAN SCHOOL MUSCAT COMPUTER SCIENCE(083) CLASS XI
INDIAN SCHOOL MUSCAT COMPUTER SCIENCE(083) CLASS XI 2017-2018 Worksheet No. 1 Topic : Getting Started With C++ 1. Write a program to generate the following output: Year Profit% 2011 18 2012 27 2013 32
More informationCMSC 201 Spring 2017 Homework 4 Lists (and Loops and Strings)
CMSC 201 Spring 2017 Homework 4 Lists (and Loops and Strings) Assignment: Homework 4 Lists (and Loops and Strings) Due Date: Friday, March 3rd, 2017 by 8:59:59 PM Value: 40 points Collaboration: For Homework
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 informationSpring 2017 CS 1110/1111 Exam 2
Spring 2017 CS 1110/1111 Exam 2 Bubble in your computing ID in the footer of this page. We use an optical scanner to read it, so fill in the bubbles darkly. If you have a shorter ID, leave some rows blank.
More informationIntroduction to Programming
Introduction to Programming Python Lab 9: Functions PythonLab9 lecture slides.ppt 27 November 2018 Ping Brennan (p.brennan@bbk.ac.uk) 1 Getting Started Create a new folder in your disk space with the name
More informationNested Loops ***** ***** ***** ***** ***** We know we can print out one line of this square as follows: System.out.
Nested Loops To investigate nested loops, we'll look at printing out some different star patterns. Let s consider that we want to print out a square as follows: We know we can print out one line of this
More informationCS 1110, LAB 1: PYTHON EXPRESSIONS.
CS 1110, LAB 1: PYTHON EXPRESSIONS Name: Net-ID: There is an online version of these instructions at http://www.cs.cornell.edu/courses/cs1110/2012fa/labs/lab1 You may wish to use that version of the instructions.
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 informationChapter 2 Input, Processing and Output. Hong Sun COSC 1436 Spring 2017 Jan 30, 2017
Chapter 2 Input, Processing and Output Hong Sun COSC 1436 Spring 2017 Jan 30, 2017 Designing a Program Designing a Program o Programs must be carefully designed before they are written. Before beginning
More informationPublic-Service Announcements
Public-Service Announcements The Computer Science Undergraduate Association(CSUA) welcomes all students interested in computer science to join them at their Welcome BBQ on Saturday, 8/27 from 12-4pm at
More informationIntro to Computational Programming in C Engineering For Kids!
CONTROL STRUCTURES CONDITIONAL EXPRESSIONS Take the construction like this: Simple example: if (conditional expression) statement(s) we do if the condition is true statement(s) we do if the condition is
More informationCMSC201 Computer Science I for Majors
CMSC201 Computer Science I for Majors Lecture 07 While Loops (cont) Last Class We Covered Using while loops Syntax of a while loop Interactive loops Infinite loops and other problems Practice with while
More information