Learn Python The Hard Way learning (24)-more exercises

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.