Previous: http://www.bkjia.com/kf/201206/136910.html
We are moving from simply inputting exercises to learning the real work of code. We need to do more exercises. The exercises below are long, so are your patience and the exercises in the next chapter. Let's get started. Make sure your input is correct.
[Python]
Print "Let's practice everything ."
Print You \ 'd need to know \ 'bout escapes with \ that do \ n newlines and \ t tabs .'
Poem = """
\ TThe lovely world
With logic so firmly planted
Cannot discern \ n the needs of love
Nor comprehend passion from intuition
And requires an explanation
\ N \ t \ twhere there is none.
"""
Print "-----------"
Print poem
Print "-----------"
Five = 10-2 + 3-6
Print "This shoshould be five: % s" % five
Def secret_formula (started ):
Jelly_beans = started * 500
Jars = jelly_beans/1000
Crates = jars/100
Return jelly_beans, jars, crates
Start_point = 10000
Beans, jars, crates = secret_formula (start_point)
Print "With a starting point of: % d" % start_point
Print "We 'd have % d beans, % d jars, and % d crates." % (beans, jars, crates)
Start_point = start_point/10
Print "We can also do that this way :"
Print "We 'd have % d beans, % d jars, and % d crates." % secret_formula (start_point)
Running result
Let's practice everything.
You 'd need to know' bout escapes with \ that do
Newlines and tabs.
-----------
The lovely world
With logic so firmly planted
Cannot discern
The needs of love
Nor comprehend passion from intuition
And requires an explanation
Where there is none.
-----------
This shoshould be five: 5
With a starting point of: 10000
We 'd have 5000000 beans, 5000 jars, and 50 crates.
We can also do that this way:
We 'd have 500000 beans, 500 jars, and 5 crates.
Extra score exercise
1. Read your code repeatedly, read your code, and comment on confusing areas.
Author: lixiang0522