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

I have attached the directions below. The topic is :

I have attached the directions below.   The topic is : How early use of technology affects child development  method of presentation: Infographic  Objective examples:ask, color, contribute, brushcollect ,comment ,complete, cut,dry, repeat, count ,finish,look at ,make, motions, mark ,jump,mix, name, open, paint,paste, pick, point to, pour,print, record ,remove, replace,return, say ,select,

“Do Hispanics with newly type II diabetics that are educated in a

PICO question is, “Do Hispanics with newly type II diabetics that are educated in a group setting have lower HGA1C’s over a three-month period than those who are educated in a traditional one-on-one setting? P- (population) – Hispanics newly diagnosed for type 2 diabetes I – (Intervention) – Implement dietary

Read and study Chapter 5 from your textbook II. Use

Read and study Chapter 5 from your textbook II. Use additional sources : LIRN Library in your course and internet articles II. List all the theories explained in the chapter III. Explain three of these theories. IV. How can you apply these  previous explained theories in the care of your

You will perform a history of a peripheral vascular problem

  You will perform a history of a peripheral vascular problem that your instructor has provided you or one that you have experienced and perform a peripheral vascular assessment. You will document your subjective and objective findings, identify actual or potential risks, and submit this in a Word document to

Topic 1 DQ 1 Accreditation is extremely important in healthcare.

 Topic 1 DQ 1 Accreditation is extremely important in healthcare. Accreditation refers to the official review process that allows healthcare organisations to demonstrate the ability to meet official regulatory standards and requirements. Accreditation is awarded upon successful completion of an on-site survey. The on-site survey is conducted by a specially

Critically appraise and evaluate whether the duties directors are

  Question: Directors transact the business of the company and are necessary because whilst a company has separate legal personality it is a legal fiction. With reference to statute and case law, critically appraise and evaluate whether the duties directors are subjected to are adequate to prevent directors abusing their

Week 7 Assignment 1 – Journal: Schools of Criminology and

  Week 7 Assignment 1 – Journal: Schools of Criminology and Your Career After reviewing the information on criminology and the four schools of criminology, discuss and give an example of how each will influence your selected criminal justice career. By submitting this paper, you agree: (1) that you are

Deadline: 11/3/2021 4:00 pm PST Please provide 5 slides with

Deadline: 11/3/2021 4:00 pm PST Please provide 5 slides with speech notes. In 2020, we experienced the start of a global pandemic, which was stressful to billions of people in the world.  Many lost their jobs and others were impacted emotionally and/or physically. You must read the required PowerPoint slides. With

There are two major forces acting against each other when

 There are two major forces acting against each other when it comes to government healthcare programs such as Medicare and Medicaid. On one end, you have the forces pushing to privatize the programs and to relinquish the government’s role in providing healthcare. On the other end, you have the forces

The Basics of a Start-Up Overview This assignment investigates the

  The Basics of a Start-Up Overview This assignment investigates the financial needs of your business venture from the first assignment, Your Business Venture.Instructions Write a 3–4 page paper in which you: Outline the financial start-up needs for this business. Consider such items as cash, equipment, space lease or purchase,

1. How do tattoos violate (or confirm) certain formal or

1. How do tattoos violate (or confirm) certain formal or informal norms? 2. What are some possible consequences for these transgressions? 3. How can concepts like cultural relativism and ethnocentrism be applied to certain styles of tattoos? 4. Do you think that tattoos are more subcultural or countercultural? 5. Have

Some people believe that you can tell who a person is by what they do when no one is looking. Let’s look at the following case. John Doe, a nurse, has downloaded an application to his phone that allow Nursing Assignment Help

Some people believe that you can tell who a person is by what they do when no one is looking. Let’s look at the following case. John Doe, a nurse, has downloaded an application to his phone that allows him to download copyrighted textbooks for a nursing course (that Doe

Discussion 1 Workplace Environment Assessment My workplace ranked at 83

 Discussion 1 Workplace Environment Assessment             My workplace ranked at 83 after filling the Clark Healthy Workplace Inventory. It is therefore moderately healthy. Although it falls short in some aspects, it is healthy and civil since great communication and cooperation exists between various departments and units. For instance, staff from

What are your beliefs regarding the effects of media on

  What are your beliefs regarding the effects of media on human behavior? How have they changed after completing this week’s reading? How has media influenced your local community, the national community, and the international community? What forms of social media have had a significant impact on human behavior? What

4 assignments. I need 1.5 Line spacing, 1 page each

4 assignments. I need 1.5 Line spacing, 1 page each for one assignment Assignment: Module 1: Information Technology and Business Applications  Assignment 1: Please write a concise (one page) position statement identifying current issues with respect to global business based on current events. What challenges do organizations face? How can

Plato’s Symposium

MLA style -pages numbered – a minimum of 1600-1800 words -each answer 3.4-4 pages -7-8 pages in total -title page included please -very specific thesis statements (then persuade) -some short quotations in support are needed -essay type questions, will need to be clear and organized -for every first order sentence/claim

Create your own Constitutional Amendment

Purpose: the purpose of this assignment includes the following: • To craft a constitutional amendment that furthers an important value crucial to a representative republic and demonstrate understanding of how a constitution differs from a law/policy. • To determine and explain how the three political cultures would view such a