magic book
magic book.md
body { font-family: var(--vscode-markdown-font-family, -apple-system, BlinkMacSystemFont, "Segoe WPC", "Segoe UI", "Ubuntu", "Droid Sans", sans-serif); font-size: var(--vscode-markdown-font-size, 14px); padding: 0 26px; line-height: var(--vscode-markdown-line-height, 22px); word-wrap: break-word }
#code-csp-warning { position: fixed; top: 0; right: 0; color: rgba(255, 255, 255, 1); margin: 16px; text-align: center; font-size: 12px; font-family: sans-serif; background-color: rgba(68, 68, 68, 1); cursor: pointer; padding: 6px; box-shadow: 1px 1px 1px rgba(0, 0, 0, 0.25) }
#code-csp-warning:hover { text-decoration: none; background-color: rgba(0, 122, 204, 1); box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.25) }
body.scrollBeyondLastLine { margin-bottom: calc(100vh - 22px) }
body.showEditorSelection .code-line { position: relative }
body.showEditorSelection .code-active-line:before, body.showEditorSelection .code-line:hover:before { content: ""; display: block; position: absolute; top: 0; left: -12px; height: 100% }
body.showEditorSelection li.code-active-line:before, body.showEditorSelection li.code-line:hover:before { left: -30px }
.vscode-light.showEditorSelection .code-active-line:before { border-left: 3px solid rgba(0, 0, 0, 0.15) }
.vscode-light.showEditorSelection .code-line:hover:before { border-left: 3px solid rgba(0, 0, 0, 0.4) }
.vscode-light.showEditorSelection .code-line .code-line:hover:before { border-left: none }
.vscode-dark.showEditorSelection .code-active-line:before { border-left: 3px solid rgba(255, 255, 255, 0.4) }
.vscode-dark.showEditorSelection .code-line:hover:before { border-left: 3px solid rgba(255, 255, 255, 0.6) }
.vscode-dark.showEditorSelection .code-line .code-line:hover:before { border-left: none }
.vscode-high-contrast.showEditorSelection .code-active-line:before { border-left: 3px solid rgba(255, 160, 0, 0.7) }
.vscode-high-contrast.showEditorSelection .code-line:hover:before { border-left: 3px solid rgba(255, 160, 0, 1) }
.vscode-high-contrast.showEditorSelection .code-line .code-line:hover:before { border-left: none }
img { max-width: 100%; max-height: 100% }
a { text-decoration: none }
a:hover { text-decoration: underline }
a:focus, input:focus, select:focus, textarea:focus { outline-offset: -1px }
hr { border-top: 0; border-right: 0; border-bottom: 2px solid; border-left: 0; height: 2px }
h1 { padding-bottom: 0.3em; line-height: 1.2; border-bottom-width: 1px; border-bottom-style: solid }
h1, h2, h3 { font-weight: normal }
table { border-collapse: collapse }
table>thead>tr>th { text-align: left; border-bottom: 1px solid }
table>thead>tr>th, table>thead>tr>td, table>tbody>tr>th, table>tbody>tr>td { padding: 5px 10px }
table>tbody>tr+tr>td { border-top: 1px solid }
blockquote { margin: 0 7px 0 5px; padding: 0 16px 0 10px; border-left-width: 5px; border-left-style: solid }
code { font-family: Menlo, Monaco, Consolas, "Droid Sans Mono", "Courier New", monospace, "Droid Sans Fallback"; font-size: 1em; line-height: 1.357em }
body.wordWrap pre { white-space: pre-wrap }
pre:not(.hljs), pre.hljs code>div { padding: 16px; border-radius: 3px; overflow: auto }
pre code { color: var(--vscode-editor-foreground); tab-size: 4 }
.vscode-light pre { background-color: rgba(220, 220, 220, 0.4) }
.vscode-dark pre { background-color: rgba(10, 10, 10, 0.4) }
.vscode-high-contrast pre { background-color: rgba(0, 0, 0, 1) }
.vscode-high-contrast h1 { border-color: rgba(0, 0, 0, 1) }
.vscode-light table>thead>tr>th { border-color: rgba(0, 0, 0, 0.69) }
.vscode-dark table>thead>tr>th { border-color: rgba(255, 255, 255, 0.69) }
.vscode-light h1, .vscode-light hr, .vscode-light table>tbody>tr+tr>td { border-color: rgba(0, 0, 0, 0.18) }
.vscode-dark h1, .vscode-dark hr, .vscode-dark table>tbody>tr+tr>td { border-color: rgba(255, 255, 255, 0.18) }
.hljs-comment, .hljs-quote { color: rgba(142, 144, 140, 1) }
.hljs-variable, .hljs-template-variable, .hljs-tag, .hljs-name, .hljs-selector-id, .hljs-selector-class, .hljs-regexp, .hljs-deletion { color: rgba(200, 40, 41, 1) }
.hljs-number, .hljs-built_in, .hljs-builtin-name, .hljs-literal, .hljs-type, .hljs-params, .hljs-meta, .hljs-link { color: rgba(245, 135, 31, 1) }
.hljs-attribute { color: rgba(234, 183, 0, 1) }
.hljs-string, .hljs-symbol, .hljs-bullet, .hljs-addition { color: rgba(113, 140, 0, 1) }
.hljs-title, .hljs-section { color: rgba(66, 113, 174, 1) }
.hljs-keyword, .hljs-selector-tag { color: rgba(137, 89, 168, 1) }
.hljs { display: block; overflow-x: auto; color: rgba(77, 77, 76, 1); padding: 0.5em }
.hljs-emphasis { font-style: italic }
.hljs-strong { font-weight: bold }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe WPC", "Segoe UI", "Ubuntu", "Droid Sans", sans-serif, "Meiryo"; padding: 0 12px }
pre { background-color: rgba(248, 248, 248, 1); border: 1px solid rgba(204, 204, 204, 1); border-radius: 3px; overflow-x: auto; white-space: pre-wrap; overflow-wrap: break-word }
pre:not(.hljs) { padding: 23px; line-height: 19px }
blockquote { background: rgba(127, 127, 127, 0.1); border-color: rgba(0, 122, 204, 0.5) }
.emoji { height: 1.4em }
code { font-size: 14px; line-height: 19px }
:not(pre):not(.hljs)>code { color: rgba(201, 174, 117, 1); font-size: inherit }
.page { page-break-after: always }
填空
class Dim:
def __init__(self,x,y):
self.x = x
self.y = y
def area(self):
pass
class Circle(Dim):
def __init__(self, r):
Dim.__init__(self, 0, r)
def area(self):
return 3.14 * self.y * self.y
class Rectangle(Dim):
def __init__(self, w, h):
Dim.__init__(self, w, h)
def area(self):
return self.x * self.y
c1 = Circle(4.0)
r1 = Rectangle(3.0,5.0)
print('圆面积',c1.area())
print('矩形面积',r1.area())
def FindWanshu():
ws = 0
lst = ""
for num in range(1,2001):
s = num
for i in range(1,num):
if num%i == 0:
s = s-i
if s == 0:
lst = lst + str(num) + ','
ws = ws+1
return lst,ws
f = open("wanshu.txt","w")
lstw,lws=FindWanshu()
f.write(lstw)
f.close()
print("1~2000之间的完数共有%d个" % lws)
print("wanshu:"+lstw)
import math
def FindSushu(lst):
for num in range(1,1000):
k = int(math.sqrt(num))
for i in range(2,k+2):
if num%i == 0:
break
if i == k+1:
lst.append(num)
f = open("sushu.txt","w")
lst = []
FindSushu(lst)
txt = ""
for item in lst:
txt += str(item)
txt += ","
f.write(txt)
f.close()
print("1~1000之间的素数共有%d个" % len(lst))
class Per:
def __init__(self,name,age):
self.name=name
self.age=age
def say_hi(self):
print("您好!我叫{0},{1}岁",format(self.name,self.age))
class Stud(Per):
def __init__(self,name,age,stu_id):
Per.__init__(self,name,age)
self.stu_id=stu_id
def say_hi(self):
Per.say_hi(self)
print('我是学生,我的学号为:',self.stu_id)
per1 = Per("张三",43)
per1.say_hi()
stu1 = Stud("李四",20,20212345678)
stu1.say_hi()
编程题
def max_n(a,b,*c):
max_value = a
if max_value < b:
max_value = b
for n in c:
if max_value < n:
max_value = n
return max_value
#测试代码
print("最大值为:",max_n(6,2))
print("最大值为",max_n(16,5,7,4,20))
import math
class MyMath:
def __init__(self,r):
self.r = r
global pi
pi = 3.14
def Perimeter(self):
return (2 * pi * self.r)
def Area(self):
return (pi * self.r * self.r)
def Surface(self):
return (4 * pi * self.r * self.r)
def Volume(self):
return (4 * pi * pow(self.r, 3) / 3)
r = float(input("请输入半径:"))
m = MyMath(r)
print(str.format("圆的周长 = {0:2.2f}",m.Perimeter()))
print(str.format("圆的面积 = {0:2.2f}",m.Area()))
print(str.format("球的表面积 = {0:2.2f}",m.Surface()))
print(str.format("球的体积 = {0:2.2f}",m.Volume()))
def getMaxMin(s):
maxi = s[0]
mini = s[0]
count = 0
for i in s:
if maxi < i:
maxi = i
if mini > i:
mini = i
count += 1
return maxi, mini, count
#测试代码
list1 = [19,20,1,2,3]
x1,y1,z1 = getMaxMin(list1)
print("list=",list1)
print("最大值=",x1,"最小值",y1,",元素个数",z1)
list2 = list2 = ["marry","lili","ben","alicei"]
x2,y2,z2 = getMaxMin(list2)
print("list=",list2)
print("最大值=",x2,"最小值",y2,",元素个数",z2)
class Temperature:
def __init__(self, degree, degree_type):
self.degree = degree
self.degree_type = degree_type
def ToFahrenheit(self):
if self.degree_type == 'C':
self.degree_type = 'F'
self.degree = (self.degree * 1.8) + 32
return self.degree
else:
return self.degree
def ToCelsius(self):
if self.degree_type == 'F':
self.degree_type = 'C'
self.degree = (self.degree - 32) /1.8
return self.degree
else:
return self.degree
#测试代码
d1 = Temperature(float(input("请输入摄氏温度:")),'C')
print(str.format("摄氏温度 = {0:2.2f},华氏温度 = {1:2.2f}",d1.ToCelsius(),d1.ToFahrenheit()))
d2 = Temperature(float(input("请输入华氏温度:")),'F')
print(str.format("华氏温度 = {0:2.2f},摄氏温度 = {1:2.2f}",d1.ToFahrenheit(),d1.ToCelsius()))
必考
import numpy as np
import matplotlib.pyplot as plt
def f(t):
return np.exp(-0.5*t) * np.cos(2*np.pi*t)
t1 = np.arange(0.0, 5.0, 0.1)
t2 = np.arange(0.0, 5.0, 0.02)
plt.figure('曲线')
plt.subplot(212)
plt.plot(t1, f(t1), 'ko', t2, f(t2), 'b')
plt.subplot(211)
plt.plot(t2,np.sin(2*np.pi*t2),'r',t1,np.cos(2*np.pi*t1+np.pi),'g-.o')
plt.show()
分析题
代码
n1 = ['张三','李四','王五','钱多']
n2 = n1
n3 = n1[:]
n2[0] = '李二'
n3[1] = '赵一'
num1=0;num2=0
for i in(n1,n2,n3):
if i[0]=='李二':
num1+=1
if i[1]=='赵一':
num2+=1
print(num1,num2)
分析结果
输出结果为:2 1
分析原因:
这段代码首先定义了一个列表n1,包含四个元素。然后创建了两个新的变量n2和n3,分别指向n1的引用和n1的一个副本。接下来,修改了n2和n3中的元素,使得它们的第0个元素变为'李二',第1个元素变为'赵一'。最后,通过遍历n1、n2和n3,统计它们中第0个元素为'李二'和第1个元素为'赵一'的次数,并将结果打印出来。
由于n2指向n1的引用,所以当修改n2的元素时,实际上也修改了n1的元素。因此,在遍历n1、n2和n3时,共有两个'李二'和一个'赵一'。
代码
x = True;y = False;z = True
if x and not z:
print('a')
elif not x or not y and not z:
print('b')
elif not x or y or not y and x:
print('c')
else:
print('d')
分析结果
输出结果为:'c'
原因分析如下:
if x and not z::x为True,z也为True,所以not z为False。因此,这个条件是False。
elif not x or not y and not z::x为True,y为False,z为True。所以not x为False,not y and not z也为False(因为y为False,z为True)。因此,这个条件也是False。
elif not x or y or not y and x::x为True,y为False,z为True。所以not x为False,y为False,not y and x也为true。因此,这个条件是true。
输出'c'。
代码
x = True;y = False;z = True
if y or not x:
print('a')
elif not x or y or not y and x:
print('b')
elif not x or not y and not z:
print('c')
else:
print('d')
分析结果
输出结果为:'b'
原因分析如下:
if y or not x::y为False,所以y or not x为False。因此,这个条件是False。
elif not x or y or not y and x::x为True,y为False,z为True。所以not x为False,y为False,not y and x为True(因为y为False,x为True)。因此,这个条件是True。输出'b'。
代码
def f(a,b):
if b==0:print('a')
else: f(b,a%b)
print(f(9,6))
分析结果
输出结果为:a None
调用 f(9 6)
进入递归条件,因为6不等于0,所以执行 f(6, 9%6)
再次进入递归条件,因为6不等于0,所以执行 f(6,3)
再次进入递归条件,因为6不等于0,所以执行 f(3,0)
在这里,由于 b 为0,打印a,递归停止。但因为函数的逻辑错误,它没有返回任何值。
由于没有返回值,print(f(9,6)) 会打印出 None
代码
count = 1;num = 0
def TestV():
global count
for i in range(3):
count+=1
num = 5
TestV()
print(count,num)
分析结果
输出结果是:4 0
分析原因如下:
count 和 num 是两个全局变量,初始值分别为 1 和 0。
TestV 函数内部使用了 global count 声明,表明该函数将访问并可能修改全局变量 count。
在 TestV 函数中,有一个循环 for i in range(3):,这个循环会执行3次。在每次循环中,全局变量 count 的值都会增加1。因此,当循环结束时,count 的值从初始的1增加到4(1+3=4)。
在 TestV 函数内部,局部变量 num 被赋值为5。注意这里的 num 是一个局部变量,而不是全局变量。因此,这个赋值操作不会影响全局变量 num 的值。
调用 TestV() 函数后,全局变量 count 的值变为4,但全局变量 num 的值仍然是0,因为函数内部的局部变量 num 并没有改变全局变量 num 的值。
最后,打印出全局变量 count 和 num 的值,即 4 0。
代码
k1 = {'a':3,'b':4}
k2 = k1
k1['a'] = 1
ksum = k1['a']+k2['a']
print(ksum)
分析结果
输出结果是:2
分析原因如下:
由于 k1 和 k2 指向同一个字典对象,当我们修改 k1['a'] 时,它实际上也修改了 k2['a'] 的值。
因此,k1['a'] 的值为1,而 k2['a'] 的值也为1(因为它们指向同一个字典对象)。
所以,ksum = k1['a'] + k2['a'] = 1 + 1 = 2。
必考
score = (65,23,-21,-34)
sum1 = 0
try:
for i in score:
if i<0 : raise ValueError(str(i)+"为负数")
sum1 += i
print('',sum1)
except Exception:
print('发生异常')
except ValueError:
print('数值不能为负')
分析结果
输出结果是:发生异常
分析原因如下:
首先,我们有一个元组 score,其值为 (65,23,-21,-34)。
初始化一个变量 sum1 为0,用于累加 score 中的元素。
进入 try 块,尝试执行其中的代码。
遍历 score 中的每个元素,对于每个元素 i:
如果 i 小于0,则抛出一个带有错误信息的 ValueError。
否则,将 i 加到 sum1 上。
在这个例子中,元素 -21 和 -34 都小于0,所以会触发 ValueError 异常。
由于在 try 块中抛出了异常,所以会进入 except Exception: 块,并打印 "发生异常"。
不会进入 except ValueError: 块,因为这里的异常是普通的 Exception,而不是 ValueError。
总结:由于元组中有负数,导致在尝试累加之前抛出了异常,所以输出结果是 "发生异常"。
magic book的更多相关文章
- Codeforces CF#628 Education 8 D. Magic Numbers
D. Magic Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- [8.3] Magic Index
A magic index in an array A[0...n-1] is defined to be an index such that A[i] = i. Given a sorted ar ...
- Python魔术方法-Magic Method
介绍 在Python中,所有以"__"双下划线包起来的方法,都统称为"Magic Method",例如类的初始化方法 __init__ ,Python中所有的魔 ...
- 【Codeforces717F】Heroes of Making Magic III 线段树 + 找规律
F. Heroes of Making Magic III time limit per test:3 seconds memory limit per test:256 megabytes inpu ...
- 2016中国大学生程序设计竞赛 - 网络选拔赛 C. Magic boy Bi Luo with his excited tree
Magic boy Bi Luo with his excited tree Problem Description Bi Luo is a magic boy, he also has a migi ...
- 一个快速double转int的方法(利用magic number)
代码: int i = *reinterpret_cast<int*>(&(d += 6755399441055744.0)); 知识点: 1.reinterpret_cast&l ...
- MAGIC XPA最新版本Magic xpa 2.4c Release Notes
New Features, Feature Enhancements and Behavior ChangesSubforms – Behavior Change for Unsupported Ta ...
- Magic xpa 2.5发布 Magic xpa 2.5 Release Notes
Magic xpa 2.5發佈 Magic xpa 2.5 Release Notes Magic xpa 2.5 Release NotesNew Features, Feature Enhance ...
- How Spring Boot Autoconfiguration Magic Works--转
原文地址:https://dzone.com/articles/how-springboot-autoconfiguration-magic-works In my previous post &qu ...
- Magic CSS3 – 创建各种神奇的交互动画效果
Magic CSS3 Animations 动画是一个独特的 CSS3 动画特效包,你可以自由地使用您的 Web 项目中.只需简单的在页面上引入 CSS 样式: magic.css 或者压缩版本 ma ...
随机推荐
- 说透IO多路复用模型
作者:京东零售 石朝阳 在说IO多路复用模型之前,我们先来大致了解下Linux文件系统.在Linux系统中,不论是你的鼠标,键盘,还是打印机,甚至于连接到本机的socket client端,都是以文件 ...
- gin框架中如何实现流式下载
作者:张富春(ahfuzhang),转载时请注明作者和引用链接,谢谢! cnblogs博客 zhihu Github 公众号:一本正经的瞎扯 团队中之前的文件下载做得比较复杂,因为担心量太大,是后台做 ...
- 人均瑞数系列,瑞数 5 代 JS 逆向分析
声明 本文章中所有内容仅供学习交流使用,不用于其他任何目的,不提供完整代码,抓包内容.敏感网址.数据接口等均已做脱敏处理,严禁用于商业用途和非法用途,否则由此产生的一切后果均与作者无关! 本文章未经许 ...
- Flask四剑客
目录 Flask四剑客 Flask四剑客 ''' 响应字符串 响应html页面 跳转页面 返回json字符串 ''' from flask import Flask, render_template, ...
- vim 从嫌弃到依赖(20)——global 命令
在前面的文章中,我们介绍了如何进行查找和替换,而替换是建立在查找基础之上的一个简单的应用,它只是将匹配文本修改为另一个.那么vim中还能针对匹配上的文本做哪些操作呢?在本篇文章中我们来对这个问题进行探 ...
- 深入浅出Java多线程(二):Java多线程类和接口
引言 大家好,我是你们的老伙计秀才!今天带来的是[深入浅出Java多线程]系列的第二篇内容:Java多线程类和接口.大家觉得有用请点赞,喜欢请关注!秀才在此谢过大家了!!! 在现代计算机系统中,多线程 ...
- C#中使用AutoMapper
AutoMapper是一种流行的对象到对象映射库,可用于映射属于不同类型的对象.例如,您可能需要将应用程序中的DTO(数据传输对象)映射到模型对象. AutoMapper省去了手动映射此类不兼容类型的 ...
- 使用symbolicatecrash工具符号化Crash日志
对于打包上线的APP,或者打包测试的APP,出现了崩溃并不能方便的把手机链接到电脑使用XCode自动符号化,此时手动符号化就是重要的选项. 1.查找符号化工具symbolicatecrash find ...
- 关于laravel路由无法访问(nginx)
laravel路由无法访问 被这个问题折腾了 好几次了,记录一下希望可以帮到后面的朋友 在laravel路由中配置好了之后无法访问的问题有可能是因为在本地服务配置的问题(我使用的是nginx服务器) ...
- 正则表达式,js、javascript 的 replace 的坑,严重留意。
一致以来我以为js的 replace 是全部替换的,没想到是只替换第一个,使用时要严重留意. 举例: let wokao: string = "abc + a_b_c + a.b.c&quo ...