前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >习题22:更多的练习

习题22:更多的练习

作者头像
py3study
发布2018-08-02 14:33:34
2010
发布2018-08-02 14:33:34
举报
文章被收录于专栏:python3python3

练习代码如下

# coding: utf-8
__author__ = 'www.py3study.com'
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('-'*50)
print(poem)
print('-'*50)
five = 10 - 2 + 3 - 6
print("This should be five:{}".format(five))
def secret_formula(started):
    jelly_beans = started * 500
    jars = jelly_beans / 1000
    crates = jars / 100
    return jelly_beans, jars, crates
started_point = 10000
print(secret_formula(started_point))
beans, jars, crates = secret_formula(started_point)
print("With a starting point of:{}".format(started_point))
print("We'd have {} beans, {} jars, and {} crates.".format(beans, jars, crates))
start_point = started_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))

应该看到的结果

图片.png
图片.png

常见问题

为什么你在后面把jelly_beans这个变量名又叫成了beans?

这是函数的工作原理,记住函数内部的变量都是临时的,当你的函数返回以后,返回值可以被赋予一个变量,这里是创建了一个新变量,用来存放函数的返回值

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017-11-14 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档