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