首页 > 编程语言 >【笨方法学python】ex24 - 更多练习

【笨方法学python】ex24 - 更多练习

时间:2022-10-06 06:11:05浏览次数:54  
标签:point python crates start beans ex24 print jars 方法学

代码如下:

点击查看代码
# coding=utf-8
# 更多练习

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 should be five: %s" % five


def secret_formula(started):
    jelly_beans = started * 500
    jars = jelly_beans / 1000
    creats = jars / 100
    return jelly_beans, jars, creats


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)

执行结果:
image

标签:point,python,crates,start,beans,ex24,print,jars,方法学
From: https://www.cnblogs.com/TiramisuPS/p/16756952.html

相关文章

  • 【笨方法学python】ex21 - 函数可以返回东西
    代码如下:点击查看代码#coding=utf-8#函数可以返回东西defadd(a,b):#加法print"ADDING%d+%d"%(a,b)returna+bdefsubtract(a,b):#......
  • 【笨方法学python】ex20 - 函数和文件
    代码如下:点击查看代码#-*-coding:utf-8--*-#函数和文件fromsysimportargvscript,input_file=argvdefprint_all(f):#定义print_all读fprin......
  • 【笨方法学python】ex19 - 函数和变量
    代码如下:点击查看代码#-*-coding:utf-8--*-#函数和变量defcheese_and_crackers(cheese_count,boxs_of_crackers): print"Youhave%dcheeses!"%cheese_cou......
  • python实验报告(第五周)
    一、实验目的和要求学会使用字符串的常用操作方法和正确应用正则表达式。二、实验环境软件版本:Python3.1064_bit三、实验过程1、实例1:使用字符串拼接输出一个关于程......
  • python字典
    字典的操作方法1.dict.get(key)根据键获取值,键不存在时返回默认值Nonedic={'a':1,'b':2}print(dic.get('a'))#输出为1print(dic.get('c'))#输出为None2.dict.......
  • Python:浮点数保留小数位数的方法整理
    示例print('%.2f'%1.255)#1.25print('{:.2f}'.format(1.2635))#1.26print(format(1.235,'.2f'))#1.24print(round(1.23456,2))#1.23参考Python保留......
  • 【WXSC】python自定义包
    沉淀自己的一些脚本和算法,托管在github或gitee上;使用的时候,直接pip安装即可,不用每次都去拷贝源码,修改源码1.构建一个本地包setup.py文件必须MANIFEST.in文件:可......
  • OpenCV-Python-C++ 全套视频详讲
    更多资料请关注公众号:计算机视觉与图形学实战​​2021OpenCV-C++课程实践(理论与实践)​​​​2021年OpenCV-Python从入门到实战全套课程(附带课程课件资料+课件笔记)​​​​......
  • C++/Python混合编程
    以C++为底层基础,Python作为上层建筑,共同搭建起高性能、易维护、可扩展的混合系统。Python本身就有C接口,可以用C语言编写扩展模块,把一些低效耗时的功能改用C实现......
  • Python语法之类和对象
    这篇文章给大家介绍一下类和对象,类和对象是面向对象编程的核心概念。Python中的类,和我们生活的“物以类聚”类似,都是包含了这一类别内都具备的一些特征。Python中的类是......