Python

 

Préambule

En 1989, le hollandais Guido van Rossum commence le développement du langage de programmation Python.

Python est un langage multiplateforme, c'est-à-dire disponible sur plusieurs architectures (compatible PC, tablettes, smartphones, ordinateur low cost Raspberry Pi...) et systèmes d'exploitation (Windows, Linux, Mac, Android...).

Le langage Python est gratuit, sous licence libre.

Mini-project description - "We want... a shrubbery!"

This mini-project is optional. Specifically, your grade on this mini-project will not count towards your final grade in this class. While this mini-project may appear silly, its purpose is important: learning how to submit and peer assess your Python mini-projects via Coursera. This mini-project is your chance to run through this process and learn how to avoid some of the simple mistakes that have plagued students in previous sessions of this class. We will walk you through each step of the process so that, next week when it is time for Rock-paper-scissors-lizard-Spock, you will understand the process completely.

The logistics of release, completion, submission and assessment of a mini-project

Before proceeding to the details of this mini-project, let's first review the general cycle of release, completion, submission and assessment of a mini-project. Here are the major steps:

  1. This mini-project description and its accompanying video describes the mini-project's requirements in detail. Each mini-project includes a detailed development process and an accompanying program template (a link to a CodeSkulptor file) that provides a good starting point for the project. Please use it.
  2. For subsequent mini-projects, the material for each mini-project also includes a page titled "Code Clinic Tips" page that includes common errors and hints. These items are based on observing 10+ sessions of students work though the associated mini-project.
  3. Once you have completed your mini-project, you can submit your mini-project by copying and pasting the CodeSkulptor URL for your code into the text box provided on the peer assessment page. (If you have trouble generating a CodeSkulptor URL, use the CodeSkulptor save service.)
  4. Once you have submitted the URL for your solution, Coursera will prompt your to assess the submissions of five of your peers. In particular, Coursera will provide you with the CodeSkulptor URLs for five of your classmate's mini-projects. Each week's mini-project has an associated grading rubric included in the assignment. You will use the pull down tabs at the bottom of the page to assign values for each rubric item to your peer's projects. As a matter of courtesy, please include a written comment if you decide not to give full score on an item. Remember that losing points with no feedback is very frustrating, so spend a little time, and explain what the problem was.
  5. Once you have assessed the work for five of your peers, your score for the assignment will be available. The score is the sum of the median of your peer's scores on each item of the grading rubric. Note that by taking the median of your peers' scores, any errors in grading by one of your peers will not affected your final grade.

The origins of Python

Python is a computer programming language that was conceived in the late 1980s by Guido van Rossum. Perhaps the most common beginner Python question is “Why would anyone name a computer language after a snake?” In fact, Python's name is derived from the television series Monty Python's Flying Circus. A common theme in the Python community is to make inside references to the television series when working with Python. Our initial mini-project honors this tradition.

Mini-project development process

Your task is simple: modify this program template to print

1
2
 
 
 
We want... a shrubbery!
 
 
 
 

in the CodeSkulptor console. Your program should consist of a single line of Python. Before submitting your program, we suggest that you review the grading rubric given below.

Grading rubric — 4 pts total

Your peers will assess your mini-project according to the following rubric. Small deviations from the textual output described above, like an extra period (.) or space are fine. Whether moderate deviations, such as just printing "shrubbery", satisfy an item of the grading rubric is at your peers' discretion during their assessment. You should avoid large deviations such as printing a different Monty Python quote. Here is a breakdown of the scoring:

  • 1 pt — A valid CodeSkulptor URL was submitted. No credit if the code is just pasted into the text box.
  • 1 pt — Running the program does not throw an error.
  • 1 pt — The program prints a message in the console.
  • 1 pt — The program prints the desired message "We want... a shrubbery!".

Practice Exercises for Variables and Assignments

Solve each of the practice exercises below. Each problem includes three CodeSkulptor links: one for a template that you should use as a starting point for your solution, one to our solution to the exercise, and one to a tool that automatically checks your solution.

  1. Given a template that pre-defines a variable miles, write an assignment statement that defines a variable feetwhose value is the number of feet in miles miles. Miles to feet template --- Miles to feet solution --- Miles to feet (Checker)
  2. Given a template that pre-defines three variables hours, minutes and seconds, write an assignment statement that updates the variable total_seconds to have a value corresponding to the total number of seconds for hours hours, minutes minutes and seconds seconds. Hours to second template --- Hours to second solution ---Hours to second (Checker)
  3. Given a template that pre-defines the variables width and height that are the lengths of the sides of a rectangle, write an assignment statement that defines a variable perimeter whose value is the perimeter of the rectangle in inches. Perimeter of rectangle template --- Perimeter of rectangle solution --- Perimeter of rectangle (Checker)
  4. Given a template that pre-defines the variables width and height that are the lengths of the sides of a rectangle, write an assignment statement that defines a variable area whose value is the area of the rectangle in square inches. Area of rectangle template --- Area of rectangle solution --- Area of rectangle (Checker)
  5. Given a template that pre-defines the constant PI and the variable radius corresponding to the radius of a circle in inches, write an assignment statement that defines a variable circumference whose value is the circumference of a circle with radius radius in inches. Circumference of circle template --- Circumference of circle solution --- Circumference of circle (Checker)
  6. Given a template that pre-defines the constant PI and the variable radius corresponding to the radius of a circle in inches, write an assignment statement that defines a variable area whose value is the area of a circle with radius radius in square inches.Area of circle template --- Area of circle solution --- Area of circle (Checker)
  7. Given the pre-defined variables present_value, annual_rate and years, write an assignment statement that define a variable future_value whose value is present_value dollars invested at annual_rate percent interest, compounded annually for years years. Future value template --- Future value solution --- Future value (Checker)
  8. Give the pre-defined variables first_name and last_name, write an assignment statement that defines the variable name_tag whose value is the string "My name is % %." where the percents should be replaced by first_name and last_name. Note that, in Python, you can use the + operator on strings to concatenate (i.e. join) them together into a single string. Name tag template --- Name tag solution --- Name tag (Checker)
  9. Given the pre-defined variables name (a string) and age (a number), write an assignment statement that defines a variable statement whose value is the string "% is % years old." where the percents should be replaced by name and the string form of age. Name and age template --- Name and age solution --- Name and age (Checker)
  10. Given the variables x0, y0, x1, and y1, write an assignment statement that defines a variable distance whose values is the distance between the points (x0,y0) and (x1,y1). Point distance template --- Point distance solution --- Point distance (Checker)
  11. Challenge: Heron's formulastates the area of a triangle is s(sa)(sb)(sc)−−−−−−−−−−−−−−−−−√ where a, b and c are the lengths of the sides of the triangle and s=12(a+b+c) is thesemi-perimeterof the triangle. Given the variables x0, y0, x1,y1, x2, and y2, write a Python program that computes a variable area whose value is the area of the triangle with vertices (x0,y0), (x1,y1) and (x2,y2). (Hint: our solution uses five assignment statements.) Triangle area template --- Triangle area solution --- Triangle area (Checker)

Practice Exercises for Expressions

Solve each of the practice exercises below. Each problem includes three CodeSkulptor links: one for a template that you should use as a starting point for your solution, one to our solution to the exercise, and one to a tool that automatically checks your solution.

  1. There are 5280 feet in a mile. Write a Python statement that calculates and prints the number of feet in 13 miles.Miles to feet template --- Miles to feet solution --- Miles to feet (Checker)
  2. Write a Python statement that calculates and prints the number of seconds in 7 hours, 21 minutes and 37seconds.Hours to seconds template --- Hours to seconds solution --- Hours to seconds (Checker)
  3. The perimeter of a rectangle is 2w+2h, where w and h are the lengths of its sides. Write a Python statement that calculates and prints the length in inches of the perimeter of a rectangle with sides of length 4 and 7 inches.Perimeter of rectangle template ---Perimeter of rectangle solution --- Perimeter of rectangle (Checker)
  4. The area of a rectangle is wh, where w and h are the lengths of its sides. Note that the multiplication operation is not shown explicitly in this formula. This is standard practice in mathematics, but not in programming. Write a Python statement that calculates and prints the area in square inches of a rectangle with sides of length 4 and 7 inches.Area of rectangle template Area of rectangle solution Area of rectangle (Checker)
  5. The circumference of a circle is 2πr where r is the radius of the circle. Write a Python statement that calculates and prints the circumference in inches of a circle whose radius is 8 inches. Assume that the constant π=3.14.Circumference of circle template --- Circumference of circle solution --- Circumference of circle (Checker)
  6. The area of a circle is πr2 where r is the radius of the circle. (The raised 2 in the formula is an exponent.) Write a Python statement that calculates and prints the area in square inches of a circle whose radius is 8 inches. Assume that the constant π=3.14. Area of circle template --- Area of circle solution --- Area of circle (Checker)
  7. Given p dollars, the future value of this money when compounded yearly at a rate of r percent interest for y years is p(1+0.01r)y. Write a Python statement that calculates and prints the value of 1000 dollars compounded at 7percent interest for 10 years. Future value template --- Future value solution --- Future value (Checker)
  8. Write a single Python statement that combines the three strings "My name is", "Joe" and "Warren" (plus a couple of other small strings) into one larger string "My name is Joe Warren." and prints the result. Name tag template --- Name tag solution --- Name tag (Checker)
  9. Write a Python expression that combines the string "Joe Warren is 52 years old." from the string "Joe Warren" and the number 52 and then prints the result (Hint: Use the function str to convert the number into a string.) Name and age template --- Name and age solution --- Name and age (Checker)
  10. The distance between two points (x0,y0) and (x1,y1) is (x0x1)2+(y0y1)2−−−−−−−−−−−−−−−−−−√. Write a Python statement that calculates and prints the distance between the points (2,2) and (5,6). Point distance template --- Point distance solution --- Point distance (Checker)


Logo Lycée Paul Sérusier

J'enseigne au
Lycée Paul SERUSIER
Avenue de Waldkappel
29270 CARHAIX PLOUGUER
Tél : 02 98 99 29 29
Site : www.lycee-serusier.fr

footer2

Richard GAUTHIER
Professeur de Physique Appliquée
Certification ISN
Cette adresse e-mail est protégée contre les robots spammeurs. Vous devez activer le JavaScript pour la visualiser.

 

 


Mentions légales


Plan du site

  Cette adresse e-mail est protégée contre les robots spammeurs. Vous devez activer le JavaScript pour la visualiser.