Introduction The purpose of this project component is to provide

 

Introduction

The purpose of this project component is to provide a first experience in the actual writing of computer programs. Using a relatively simple introductory scripting language (Python), you will create program code in an editor (Notepad), save it to your disk, and run it from the command line prompt.

You will gain experience in planning, writing, debugging, documenting, and running simple programs. Learning Python serves as a convenient stepping-stone to more complex object-oriented languages, such as Java.

In this project, you will use online resources, including downloadable Python tools and tutorials.

Before writing programs, it is useful to plan the programming steps and actions by writing an algorithm. An algorithm is a set of plain English language commands or steps, each of which is then replaced by the appropriate command line for the programming language used. This technique becomes less useful when using complex object-oriented languages such as Java, but may be helpful in the early stages of learning to design programs. You will write algorithms for your first two programming exercises in this project.

The project will be graded for completeness and correct functioning of programs.

Acquiring the Tools

Download and install Python version 2.2 or higher by following the instructions at the Python download site.

The downloaded file will be called Python-2_2.exe. After downloading, run this file to complete the installation. You can view the installed components from your “Start” list.

Writing Algorithms

In the traditional approach to programming, the program is seen as a series of steps, which may include branches and loops. A branch occurs when a program may go in two or more different directions, depending upon a logical condition or a choice made by the user. A loop is a situation where a particular step, or series of steps, may be repeated until a certain condition or choice occurs.

The following simple example of an algorithm includes both elements, and describes a simple program for performing addition or multiplication.

Step 1—display the program name “Addition and Multiplication”

Step 2—display the options menu “(A)dd, (M)ultiply”

Step 3—request and store input of user choice A or M as “choice”

Step 4—if “choice” does not equal “A” or “M”, go to Step 9

Step 5—request and store the first number to be used as variable X

Step 6—request and store the second number to be used as variable Y

Step 7—if “choice” = “A” go to Step 11

Step 8—if “choice” = “M” go to Step 13

Step 9—display message “Choose A or M”

Step 10—go to Step 3

Step 11—display “Sum is” X+Y

Step 12—go to Step 3

Step 13—display “Product is” X*Y

Step 14—go to Step 3

Writing, Storing, and Running Python Programs

The actions involved in creating and running Python programs are relatively simple:

Input the code using Notepad, and save the file as *.py (e.g., prog1.py). Save your programs in the Python folder on your hard disk.

Open the MS-DOS prompt window.

Change directory from Windows to Python22 (enter “cd”, followed by “cd python22”).

Run the Python interpreter on your program by typing python filename.py, where “filename” is the actual name of your saved *.py file (e.g., python prog1.py).

Learning Python

Go to A Beginner’s Python Tutorial, and work through the first seven lessons.

Please note that the tutorial describes running programs for an earlier version of Python, and follows:

“Edit” menu-> “Run Script”

In later versions of Python, programs are run as follows:

“Run” menu-> “Run Module” (or simply hit F5)

Note: If you need more help, the internet has several instructive sites, for example, www.learnpython.org/.

Programs

The programs you will write for this project are copied with permission, or adapted from, the exercises in A Beginner’s Python Tutorial.

Each program should be written, tested, and debugged. The first two programs should also be fully commented, with each line documented by a descriptive comment. The remaining programs should have a single comment line at the beginning to describe the function of the program. All programs should start with a display of your name, student id#, and the program number and name. When storing the files, name them as prog1.py, prog2.py, etc.

EXAMPLE OF AUTHOR/PROGRAM INFORMATION OUTPUT

Program author: B. Rubble

ID#: 1234567

Program 1—Math Functions

PROGRAM 1—MATH FUNCTIONS

Write an algorithm for a program that shows the use of all six math functions. Write, test, and debug the program using Python.

SAMPLE OUTPUT (not including author/program information)

ADDITION: 2+2=4

SUBTRACTION: 4-2=2

MULTIPLICATION: 4*2=8

DIVISION: 4/2=2

EXPONENT: 2**3=8

REMAINDER: 5%2=1

PROGRAM 2—USING INPUT

Write an algorithm for a program that receives, as input from the user, 2 string variables and 2 integer variables; then joins together and displays the combined strings; and finally multiplies the two numbers on a new line. Write, test, and debug the program using Python.

SAMPLE OUTPUT (not including author/program information)

Input string 1? Billy

Input String 2? Bob

Input integer A? 23

Input integer B? 2

BillyBob

46

PROGRAM 3—LOOPS AND IF CONDITIONS

Write a program that requests a password after the author/program information is displayed. Make the password “hello”. The program should then ask the user for their name: if the name entered is the same as your name, the program should respond with “What a great name!”; if they enter “Madonna” or “Cher”, the program should respond “May I have your autograph, please?”. For any other input, the program should respond with “(input name), that’s a nice name”.

SAMPLE OUTPUT (including author/program information)

Program author: Barney Rubble

ID#: 1234567

Program 3—LOOPS AND IF CONDITIONS

Password? unicorn

Password? opus

Password? hello

Welcome to the second half of the program!

What is your name? Barney

What a great name!

ALTERNATE OUTPUTS

What is your name? Cher

May I have your autograph, please?

What is your name? Bill

Bill, that’s a nice name.

PROGRAM 4—FUNCTIONS

Rewrite the area.py program (shown below, or in the Creating Functions section of the tutorial) so that it has separate functions for the perimeter and area of a square, a rectangle, and a circle (3.14 * radius**2). This program should include a menu interface that has ‘exit the program’ as one of its choices.

SAMPLE PROGRAM EXECUTION

Area.py

#This program calculates the perimeter and area of a rectangle

print “Calculate information about a rectangle”

length = input(“Length:”)

width = input(“Width:”)

print “Area”,length*width

print “Perimeter”,2*length+2*width

SAMPLE OUTPUT (not including author/program information)

CALCULATIONS MENU

1) AREA (SQUARE)

2) AREA (RECTANGLE)

3) AREA (CIRCLE)

4) PERIMETER (SQUARE)

5) PERIMETER (RECTANGLE)

6) PERIMETER (CIRCLE)

7) EXIT

INPUT MENU CHOICE (1,2,3,4,5,6 OR 7)? 2

YOU HAVE CHOSEN AREA (RECTANGLE)

INPUT WIDTH? 8

INPUT LENGTH? 4

AREA IS 32

INPUT MENU CHOICE?

Packaging and Submitting

When submitting your project, use WinZip or a compatible program to compress all the required files into a single archive. There should be four files in total: prog1.py, prog2.py, prog3.py, and prog4.py.4

Share This Post

Email
WhatsApp
Facebook
Twitter
LinkedIn
Pinterest
Reddit

Order a Similar Paper and get 15% Discount on your First Order

Related Questions

Discuss a prominent environmental or sustainability practice employed by any

  Discuss a prominent environmental or sustainability practice employed by any company that you believe has been forward-thinking and successful in its efforts How have their policies impacted the company, society, and the environment?. Support your response by integrating source evidence using SWS-style citations.  The textbook may be used as

Budget in Service Company (Cash Budget) Edge Soccer Program (Edge)

Budget in Service Company (Cash Budget) Edge Soccer Program (Edge) began the year with a cash balance of $10,500. The budget forecasts that collections from company owed to the company by customers will be $11,000 in January and $15,200 in February. The soccer program is also supposed to receive $8,500

Managing Ethics and Corporate Social Responsibility

Managing Ethics and Corporate Social Responsibility l Paper details 1.As a leader, what five things can YOU do in YOUR job to increase the probability of ethical behavior by others in your organization? Please tailor these action items to your specific strengths, position, and expected role. Describe at length why

In your initial post, share one example of a good

In your initial post, share one example of a good graphical representation of data and one example of a bad graphical representation of data. These can be anything you find online, in print, or elsewhere. For each of your two examples, include why you think they are good and bad

Malcolm X Literacy Discussion Board 7272 unread replies.7272 replies. First,

  Malcolm X Literacy Discussion Board 7272 unread replies.7272 replies. First, did you read the Module 2: Overview? This set of instructions includes links in blue font to help guide you.  Read this following PDF article from Malcolm X: “Literacy Behind Bars.”  Then, complete the following.  Summarize the article in

Share your thoughts on two or more of the reflection

Share your thoughts on two or more of the reflection questions: Questions In what ways do children manage transitions? In what ways can we support parents to communicate the unique needs of their child as they transition between home and preschool? How do adults respond to children’s care aware of

WOHS Cancer Testing Discussion Nursing Assignment Help

I’m working on a health & medical discussion question and need the explanation and answer to help me learn. A 65-year-old black male visits his physician with complaints including bone pain in his spine and hips, excessive thirst, numbness in his legs, and sporadic mental confusion. The patient also explained

Using what you know about your personal leadership style and

 Using what you know about your personal leadership style and the tenets of servant leadership, explain why it is important to be able to meld these principles together as a public health professional and leader. Provide two suggestions for doing so. In replies to peers, discuss whether you agree or

Task 1. Select a foreign country from which you would

Task1. Select a foreign country from which you would be investing.  2. Prepare a 2-3 paragraph statement of your investment strategy, risk profile, and reason for investing in the US as opposed to in your “home” country.3. With the justifications you provide in task 3 in mind, please state in

UTILZE the attachment which consists of 200 MBA students at

  UTILZE the attachment which consists of 200 MBA students at Whatsamattu U. It includes variables regarding their age, gender, major, GPA, Bachelors GPA, course load, English speaking status, family, and weekly hours spent studying.  1.Perform a categorical analysis on the majors of students enrolled in the MBA. Describe your

Requirements: I need unique and a little bit professional answers

Requirements: I need unique and a little bit professional answers free plagiarism, good grammar. Total 850 words, Support your answers with course material concepts, principles, and theories from the case study given and the files I uploaded, I need at least two scholarly or academic, journal articles references in APA

This week you have learned about how the food you

  This week you have learned about how the food you eat influences your metabolism and digestive processes. When considering these digestive processes, we tend to think about the organs of the gut, including the colon; however, it turns out there are other cells that are just as important to

Part 1 Scenario Mary, Jill, Paula, and Petra formed Green

Part 1 Scenario Mary, Jill, Paula, and Petra formed Green Envy Co., a C corporation, on January 2, Year 1. Information regarding each shareholder’s contributions and stock ownership is provided at the link below.   Using the information provided, complete the table in Part 1 of the Excel spreadsheet by

You will research and write a paper analyzing the cultural

 You will research and write a paper analyzing the cultural perspectives of doing business in another nation. The nation chosen is South Korea.  · Length of assignment: 10 pages minimum. 10 pages is approximately 2,500 words of content, that does not include the Title Page, Table of Contents, Abstract, or

Supply Chain Management: LOG301 SLP1

Please begin by reading Anderson et al. (1997), with particular attention to their seven SCM principles. All of these will be covered in the following modules, if not in the same sequence as the authors. During this session long project, you will analyze a logistics firm such as UPS, FedEx,

Opportunity cost of your resource is defined as “the value

Opportunity cost of your resource is defined as “the value associated with the next best use of that resource (which you must give up).” Decisions you make should reflect your opportunity cost, and not just your out-of-pocket costs. For example, if you decide to spend two hours of your time

Topic: What is a human being, according to Descartes? Explain

Topic: What is a human being, according to Descartes? Explain clearly his argument for his position, focusing on the sense in which the mind and the body can be both distinct and one thing (i.e. form a union). Consider what you take the strongest criticism of Descartes’s position to be