【Python】Learn Python the hard way, ex24 函数综合练习

#coding:utf-8
print "Let's practice everything."
print "You\'d need to konw \'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 should 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 crares." % (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) 


'''
Test Result:

Let's practice everything.
You'd need to konw '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 should be five: 5
With a starting point of: 10000
We'd have 5000000 beans, 5000 jars, and 50 crares.
We can also do that this way:
We'd have 500000 beans, 500 jars, and 5 crates.
'''


函数可以返回多个值,学到了,以前以为以此只能返回一个值


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Python进阶书籍,Transform Your Ideas into High-Quality Python Code! Zed Shaw has perfected the world’s best system for becoming a truly effective Python 3.x developer. Follow it and you will succeed—just like the tens of millions of programmers he’s already taught. You bring the discipline, commitment, and persistence; the author supplies everything else. In Learn Python 3 the Hard Way, Zed Shaw taught you the basics of Programming with Python 3. Now, in Learn More Python 3 the Hard Way, you’ll go far beyond the basics by working through 52 brilliantly crafted projects. Each one helps you build a key practical skill, combining demos to get you started and challenges to deepen your understanding. Zed then teaches you even more in 12 hours of online videos, where he shows you how to break, fix, and debug your code. First, you’ll discover how to analyze a concept, idea, or problem to implement in software. Then, step by step, you’ll learn to design solutions based on your analyses and implement them as simply and elegantly as possible. Throughout, Shaw stresses process so you can get started and build momentum, creativity to solve new problems, and quality so you’ll build code people can rely on. Manage complex projects with a programmer’s text editor Leverage the immense power of data structures Apply algorithms to process your data structures Master indispensable text parsing and processing techniques Use SQL to efficiently and logically model stored data Learn powerful command-line tools and skills Combine multiple practices in complete projects It’ll be hard at first. But soon, you’ll just get it—and that will feel great! This course will reward you for every minute you put into it. Soon, you’ll go beyond merely writing code that runs: you’ll craft high-quality Python code that solves real problems. You’ll be a serious Python programmer. Perfect for Everyone Who’s Already Started Working with Python, including Junior Developers and Seasoned Python Pr
### 回答1: 《学习Python的硬道理》是一本非常受欢迎的Python编程学习教程。它是由Zed Shaw编写的,以实践为基础的学习方法,具有适合初学者的特点。 这本教程通过一系列的练习和示,帮助读者逐步掌握Python编程的基础知识和技能。它强调通过不断实践和写代码来学习,而不只是被动地阅读理论知识。实践中的困难会迫使学习者主动思考和解决问题,这也是为什么它被称为"学习Python的硬道理"。 该教程提供了一些实用的技巧和建议,帮助初学者更好地理解和掌握Python编程。通过逐步实现一些小项目和练习题,读者可以逐渐提升自己的编程能力。 与其他教程相比,这本教程更倾向于通过实践学习,并鼓励读者多写代码和尝试不同的方法。这样的学习方式对于编程入门者来说非常有益,因为它使他们能够更深入地理解编程的核心思想和概念。 总而言之,《学习Python的硬道理》是一本很好的Python编程学习教程,特别适合初学者。通过它,读者可以获得坚实的编程基础,并能够在实践中不断提升自己的技能。 ### 回答2: 《Learn Python the Hard Way(笨办法学Python)》是一本广受欢迎的Python编程入门书籍,主要通过实践和练习来帮助读者掌握Python编程语言。 这本书的PDF版本非常受欢迎,因为它提供了免费的学习资源,可以随时随地进行学习。通过下载这个PDF文件,读者可以在没有网络连接的情况下进行学习,并且可以根据自己的进度学习。 《Learn Python the Hard Way》这本书的特点是以实践为重,通过编写和运行代码来学习Python编程。它提供了大量的练习题和习题答案,帮助读者巩固所学的知识,并培养解决问题的能力。 这本书适合初学者学习Python编程,无论是有编程经验还是没有编程经验的读者都可以从中受益。它从基础知识开始,逐步介绍了Python的各个方面,包括变量、函数、循环、条件语句等等。通过实践和编程练习,读者可以逐渐掌握Python的编程技巧和应用。 总之,学习Python的最佳途径是通过实践来掌握。《Learn Python the Hard Way》的PDF版本提供了免费的学习资源,可供读者随时随地进行学习。通过实践和编程练习,读者可以快速掌握Python编程的基础知识和技巧。这本书尤其适合初学者,无论有无编程经验,都可以通过学习它来迅速入门Python编程。 ### 回答3: "Learn Python the Hard Way"是一本非常受欢迎的Python编程入门书籍,由Zed A. Shaw撰写。该书旨在帮助初学者通过实际的编程练习来学习Python语言。 这本书的一个主要特点是通过一系列的编程练习来进行学习,每个练习都有详细的说明和示范代码。学生需要阅读相关材料,并按照书中的指导进行代码编写和测试。通过这种刻意练习的方法,学生可以逐步适应并掌握Python的语法、逻辑和编程思维。 "Learn Python the Hard Way"强调了编程的实践重要性,鼓励学生不断尝试、理解和解决问题。通过完成一些较为复杂的编程练习,学生可以逐步提高他们的编程能力和解决问题的技巧。 该书所提供的练习和教学方法不仅适合初学者,也适用于那些希望通过实践来巩固他们的Python知识的中级学习者。 总的来说,"Learn Python the Hard Way"是一本适合通过实践来学习Python编程的入门教材。它通过一系列的编程练习帮助学生逐步掌握Python的基础知识和编程技巧,是一本非常实用和受欢迎的Python学习资源。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值