python习题19

 1 def cheese_and_crackers(cheese_count, boxes_of_crackers):
 2     print(f"You have {cheese_count} cheese!")
 3     print(f"You have {boxes_of_crackers} boxes fo crackers!")
 4     print("Man that‘s enough for a party!")
 5     print("Get a blanknet.\n")
 6
 7
 8 print("We can just give the function numbers directly:")
 9 cheese_and_crackers(20,30)
10
11
12 print("OR, we can use variables from our script:")
13 amount_of_cheeses = 10
14 amount_of_crackers = 50
15
16 cheese_and_crackers(amount_of_cheeses, amount_of_crackers)
17
18
19 print("We can even do math inside too:")
20 cheese_and_crackers(10 + 20, 5 + 6)
21
22 print("And we can combine the two, variables and math:")
23 cheese_and_crackers(amount_of_cheeses + 100, amount_of_crackers + 1000)
 1 def book_123(book_page, book_jiage,book_zishu):
 2     print(f"这本书一共有 {book_page}页,约{book_zishu}万字。")
 3     print(f"这本书的价格是{book_jiage}元。")
 4
 5
 6 print("001:我刚刚买了一本书。")
 7 book_123(50,20,10)
 8
 9 print("002:我换一种方式说。")
10 page = 50
11 zishu = 20
12 jiage = 10
13
14 book_123(page, zishu, jiage)
15
16 print("003:我换一本五倍的书试试。")
17 book_123(page * 5, zishu * 5, 50)
18
19 print("004:继续。")
20 book_page = int(input(">>>>"))
21 book_jiage = int(input(">>>>"))
22 book_zishu = int(input(">>>>"))
23
24 book_123(book_page + 1, book_jiage + 1,book_zishu + 1)

原文地址:https://www.cnblogs.com/shadowyuriya/p/10061380.html

时间: 2024-10-11 07:55:06

python习题19的相关文章

欧拉计划(python) problem 19

Counting Sundays Problem 19 You are given the following information, but you may prefer to do some research for yourself. 1 Jan 1900 was a Monday. Thirty days has September, April, June and November. All the rest have thirty-one, Saving February alon

笨方法学Python——习题40

之前例子讲过关于字典.列表.字符串.元组,按书中所述,其实这些已经足够写一些代码,但Python属于面向对象的编程语言,本节所讲的类,是必须要掌握的,虽然现在有些懵逼 1 class Song(object): 2 3 def __init__(self, lyrics): 4 self.lyrics = lyrics 5 6 def sing_me_a_song(self): 7 for line in self.lyrics: 8 print line 9 10 happy_bday = S

python习题16

1 from sys import argv 2 3 script, filename = argv 4 5 print(f"We're going t o erase {filename}.") 6 print("If you don't want that, hit CTRL-(^C).") 7 print("If you do want that, hit RETURN.") 8 9 input("?") 10 11 p

python习题15

1 # 从python的内置模块中引入模组 2 from sys import argv 3 4 # 解包,获取文件名 5 script, filename = argv 6 7 #返回某文件对象 8 txt = open(filename) 9 10 #打印这句话,嵌入文件名 11 print(f"Here's your file {filename}:") 12 #读取文件内容并且打印 13 print(txt.read()) 14 15 print("Type the

笨办法学Python - 习题3: Numbers and Math

Exercise2是注释和井号 Comments and Pound Characters 具体详情请参考习题一,这里就不在做过多的赘述. 习题 3: 数字和数学计算 学习目标:了解Python中常用的算术运算符,并了解运算符之间的先后运算顺序 在各大常用的计算机语言中都有常见的算术运算符,Python也是大同小异,下面我们来了解一下Python中常见的算术运算符: 算术运算符 以下假设变量x = 10 ,y = 20 运算符 描述 实例 + 加 - 两个对象相加 x+y = 30 - 减 -

笨办法学Python - 习题8-10: Printing & Printing, Printing

目录 1.习题 8: 打印,打印 2.习题 9: 打印,打印,打印 3.习题 10: 那是什么? 3.1.转义序列: 4.习题总结: 1.习题 8: 打印,打印 学习目标:继续学习 %r 的格式化输出. 习题八中的练习代码是: #! -*-coding=utf-8 -*- formatter = "%r %r %r %r %r " print formatter % (1, "hello", [1,2,3], (1,2,3), {"name":&

python习题20190130

#encoding=utf-8 ''' 一家商场在降价促销.如果购买金额50-100元(包含50元和100元)之间,会给10%的折扣,如果购买金额大于100元会给20%折扣.编写一程序,询问购买价格,再显示出折扣(10%或20%)和最终价格 ''' def print_zekou(): aount = int(input("请输入你购买的金额:")) if aount < 50: print("不好意思你购买的金额没有折扣,需要支付的金额为:",aount)

python习题练习(chapater 5 -- python核心编程)

更新中... #!/usr/bin/env python# coding: utf-8'for practise in chapater five' #定义一个函数,计算并返回两个数的乘机def product(a, b): return(a * b) #根据分数输出同学的评分成绩(A-F)def score(i): if (i > 90) & (i < 100):  return('A') elif (i > 80) & (i < 89):  return('B'

Python学习-19.Python的Http模块

模拟 http 请求是比较常见的一种需求,在 Python 中,使用 http 模块操作. 1 import http.client 2 3 # 创建 Http 连接. 4 http = http.client.HTTPConnection('www.baidu.com') 5 # 设置请求,第一个参数为请求方法,第二个参数为请求的页面. 6 http.request('GET','/') 7 # 获取百度主页的内容,返回的是一个 bytes. 8 html = http.getresponse