liveBook · Manning

Application

As explained in Get Programming: Learn to code with Python

A program is an executable sequence of instructions that directs a computer to perform a task.

A program is a sequence of statements that directs a computer to do a task. A small program might convert a measurement; another might help you organize personal records. You do not need to be a professional programmer to write one that meets a particular need. section 6.0 section 1.1

To make a first program, turn the task into smaller steps:

Convert minutes to hours and minutes

Start with 123 minutes. Divide by 60 and convert the result to an integer to get 2 whole hours. The remainder after division by 60 is 3 minutes. Print both values. This program has four clear parts: initialize the input, find the hours, find the remaining minutes, and display the answer. section 6.5

Listing 6.2. Convert minutes to hours and minutes using the remainder
minutes_to_convert = 123                               #1

hours_decimal = minutes_to_convert/60                  #2
hours_part = int(hours_decimal)                        #3

minutes_part = minutes_to_convert%60                   #4

print("Hours")
print(hours_part)
print("Minutes")
print(minutes_part)

Follow the short Python listing from the starting value through the two calculations to the printed result. The % operation supplies the minutes left over. section 6.5

A program can grow with the task. It can ask for names and combine parts of them, read a structured file of contacts for analysis, or respond to clicks in a window. Plan what it must do before writing code, then build and check one part at a time. section 12.5 section 23.0 section 37.5 section 12.2

How Get Programming: Learn to code with Python covers it

How deep it goes
Works through a complete Python conversion program step by step, including an alternative calculation; does not descend into how computers execute statements.
Examples
Uses minute conversion, a name mashup, an art-word game, contact-file analysis, and a graphical phonebook as concrete projects.
What it assumes
Starts with basic programming ideas and encourages hands-on practice without assuming prior programming experience.
What you can do after
Build it from scratch: plan a task, write a small Python program with calculations or input, and print a result.
How it connects
Connects programs to statements, variables, expressions, input, output, conditionals, loops, files, classes, and graphical user interfaces.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Get Programming: Learn to code with Python. The section links point to the parts of the book it draws on.