ex19.py

 1 # -*- coding:utf-8 -*-
 2 def cheese_and_crackers(cheese_count, boxes_of_crackers):
 3     print ("You Have %d cheeses!" % cheese_count)
 4     print ("You have %s boxes of crackers!" % boxes_of_crackers)  # 掌握格式符的用法%r %s %d
 5     print ("Man that‘s enough for a party!")
 6     print ("Get a blanket.\n")
 7
 8 print ("We can just give the function numbers directly:")
 9 cheese_and_crackers(20,30)
10
11 print ("OR,we can use variables from our script:")
12 amount_of_cheese = int(float(input(">>>"))) #掌握这两个函数的套用
13 amount_of_crackers = input(">>>>")
14
15 cheese_and_crackers(amount_of_cheese,amount_of_crackers)
16
17 print ("We can even do math inside too:")
18 cheese_and_crackers(10 * 20,5 + 6)
19
20 print ("And we can combine the two, variables and math")
21 cheese_and_crackers(amount_of_cheese + 100, amount_of_crackers + "100")
时间: 2024-10-19 15:40:32

ex19.py的相关文章

python练习题-20170916

周末开始第一次尝试对着书写代码练习题 <笨办法学python>--作者Zed A.Shaw,翻译Wang Dingwei ex1.pyprint('hello world')---------------------------------------ex2.py #A comment, this is so you can read your program later.#Anything after the # is ignored by python. print('i could ha

python中split()、os.path.split()函数用法

一.Python split() 通过指定分隔符对字符串进行切片,如果参数 num 有指定值,则仅分隔 num 个子字符串 str.split(str="", num=string.count(str)). 参数: str -- 分隔符,默认为所有的空字符,包括空格.换行(\n).制表符(\t)等. num -- 分割次数. 返回值:返回分割后的字符串列表. split():拆分字符串.通过指定分隔符对字符串进行切片,并返回分割后的字符串列表(list) sentence="

使用TDD理解views.py与urls.py的关系

首先必须对MVC的概念有初步的认识,django也遵循这样一套规范,views.py相当于视图函数,是整个架构中的处理引擎,而urls.py的作用就是将用户请求送入这样的引擎. 项目结构: urls.py: from django.conf.urls import include, url from django.contrib import admin urlpatterns = [ # Examples: #url(r'^$', 'mysite.views.home', name='home

layers.py cs231n

如果有错误,欢迎指出,不胜感激. import numpy as np def affine_forward(x, w, b): 第一个最简单的 affine_forward简单的前向传递,返回 out,cache """ Computes the forward pass for an affine (fully-connected) layer. The input x has shape (N, d_1, ..., d_k) and contains a minibat

Python pydoc.py

1. 查看帮助,我们可以在python命令行交互环境下用 help函数,比如: 查看 math 模块: >>> help('math')Help on built-in module math: NAME math DESCRIPTION This module is always available. It provides access to the mathematical functions defined by the C standard. FUNCTIONS acos(..

创建py模板

创建模板之后,每次新建py文件,已初始定义的代码段将会自动出现在py文件中.

python下编译py成pyc和pyo

其实很简单,用python -m py_compile file.py python -m py_compile /root/src/{file1,file2}.py编译成pyc文件.也可以写份脚本来做这事:Code: import py_compile py_compile.compile('path') //path是包括.py文件名的路径 用python -O -m py_compile file.py 编译成pyo文件.1.其中的 -m 相当于脚本中的import,这里的-m py_co

django 运行python manage.py sqlall books 时报错 app has migration

出现这个问题的原因是版本之前的不兼容,我用的django版本是1.8.6 而 这条python manage.py sqlall books 是基于django1.0版本的. 在django1.8.6版本中生成一个表的语句是    $ python manage.py makemigrations books $ python manage.py sqlmigrate books 0001 django book2 是一本不错的教程,但是就是版本太老了,可以通过看book2对django有一个比

word2vec_basic.py

ssh://[email protected]:22/usr/bin/python3 -u /home/win_pymine_clean/feature_wifi/word2vec_basic.py Found and verified text8.zip Data size 17005207 Most common words (+UNK) [['UNK', 418391], ('the', 1061396), ('of', 593677), ('and', 416629), ('one',