Lesson 6. Capstone project: your first Python program—convert hours to minutes

 

After reading lesson 6, you’ll be able to

  • Read your first programming problem
  • Walk through two possible solutions
  • Write your first Python program

Here are some of the main ideas you should be familiar with so far:

  • Programs are made up of a sequence of statements.
  • Some statements initialize variables.
  • Some statements can be expressions to do calculations.
  • Variables should be given descriptive and meaningful names, especially to help future programmers who might be looking at the code.
  • Some calculations you’ve seen so far are addition, subtraction, multiplication, division, remainder, and power.
  • You can convert an object to a different type.
  • The print command can be used to show output to the console.
  • You should write comments in the code to document what the code is doing.
The problem

The first programming task you’ll see is to write a program in Python that converts minutes to hours. You’ll start with a variable that contains the number of minutes. Your program will take that number, do some calculations, and print out the conversion to hours and minutes.

Your program should print the result in the following way. If the number of minutes is 121, the program should print this:

Hours
2
Minutes
1

6.1. Think-code-test-debug-repeat

 

6.2. Divide your task

 
 
 
 

6.3. Implement the conversion formula

 
 

6.4. Your first Python program: one solution

 
 

6.5. Your first Python program: another solution

 
 

Summary

 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage