A Python program in "A book that gently teaches difficult programming"

I will copy the Python program of "A book that teaches difficult programming easily". By the way, the evaluation is low on Amazon, but the reason seems to be that the title "Tell me gently" is not. Conversely, for those who look at Qiita, this book, which carefully describes data structures, pointers, classes, object orientation, etc., seems to be a good book. Of course, it's not a stemmer.

p.128 Listing 1

ball.py


a=4/3
p=3.14
r=15/2
r3=r**3

print(a*p*r3)

p.129 Listing 3

ball.py


a=4/3
p=3.14
r=15/2
r3=r**3

print(a*p*r3)

def show(name, val):
    return name + '=' + str(val)

print( show("a", a) )
print( show("p", p) )
print( show("r", r) )
print( show("r3", r3) )

p.129 Figure 14

>>> varNames = ['a', 'p', 'r', 'r3']
>>> for i in range(len(varNames)):
        print(varNames[i])
>>> for d in varNames:
    print(d)

p.129 Figure 15

>>> varNames = ['a', 'p', 'r']
>>> varNames.remove('a')
>>> varNames
>>> varNames.insert(0, 'a')
>>> varNames
>>> varNames.append('r3')
>>> varNames

p.130 Figure B

import ui
import console

def button_tapped(sender):
    console.alert("Hello", "The button was pressed", "OK")

button = ui.Button(title="button")
button.action = button_tapped
button.present("sheet")

p.185 Listing 1 Using the Euclidean algorithm to calculate the greatest common divisor (gcd)


def gcd(a, b):
    return a if b == 0 else gcd(b, a % b)
print(gcd(342, 162))

Recommended Posts

A Python program in "A book that gently teaches difficult programming"
A program that removes duplicate statements in Python
A general-purpose program that formats Linux command strings in python
I tried "a program that removes duplicate statements in Python"
When writing a program in Python
A program that determines whether a number entered in Python is a prime number
Spiral book in Python! Python with a spiral book! (Chapter 14 ~)
[Python] A program that creates stairs with #
I made a payroll program in Python!
Write a Caesar cipher program in Python
Try a functional programming pipe in Python
A program that plays rock-paper-scissors using Python
Learn dynamic programming in Python (A ~ E)
[Python] A program that rounds the score
Programming in python
Ant book in python: Sec. 2-3, Dynamic Programming (DP)
A memo that I wrote a quicksort in Python
A simple Pub / Sub program note in Python
I made a Caesar cryptographic program in Python.
[Beginner] What happens if I write a program that runs in php in Python?
Python programming in Excel
[Python] A program that counts the number of valleys
I made a prime number generation program in Python
Write a super simple molecular dynamics program in python
Receive dictionary data from a Python program in AppleScript
Try embedding Python in a C ++ program with pybind11
From a book that programmers can learn ... (Python): Pointer
What's in that variable (when running a Python script)
In Python, create a decorator that dynamically accepts arguments Create a decorator
A shell program that becomes aho in multiples of 3
I made a prime number generation program in Python 2
[Python] A program that compares the positions of kangaroos.
A Python program that converts ical data into text
MALSS, a tool that supports machine learning in Python
[Python] A program that finds the shortest number of steps in a game that crosses clouds
A note that runs an external program in Python and parses the resulting line
Take a screenshot in Python
Create a function in Python
Create a dictionary in Python
A function that divides iterable into N pieces in Python
Published a library that hides character data in Python images
From a book that programmers can learn ... (Python): About sorting
Loop through a generator that returns a date iterator in Python
Let's create a script that registers with Ideone.com in Python.
A word that I was interested in as a programming beginner
A program that automatically resizes the iOS app icon to the required image size in Python
From a book that programmers can learn (Python): Decoding messages
Summary of points to keep in mind when writing a program that runs on Python 2.5
[Python] Programming to find the number of a in a character string that repeats a specified number of times.
[Python] A program that creates a two-dimensional array by combining integers
I made a program to collect images in tweets that I liked on twitter with Python
Make a bookmarklet in Python
Create code that outputs "A and pretending B" in python
[MQTT / Python] Implemented a class that does MQTT Pub / Sub in Python
"A book to train programming skills to fight in the world" Python code answer example --1.8 "0" matrix
[Python] A program that finds the most common bird types
Draw a heart in Python
A Python program that aggregates time usage from icalendar data
A set of script files that do wordcloud in Python3
[Python] Dynamic programming TDPC A
A Python program that collects tweets containing specific keywords daily and saves them in csv