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的更多相关文章

  1. 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 ...

  2. [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 ...

  3. Python魔术方法-Magic Method

    介绍 在Python中,所有以"__"双下划线包起来的方法,都统称为"Magic Method",例如类的初始化方法 __init__ ,Python中所有的魔 ...

  4. 【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 ...

  5. 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 ...

  6. 一个快速double转int的方法(利用magic number)

    代码: int i = *reinterpret_cast<int*>(&(d += 6755399441055744.0)); 知识点: 1.reinterpret_cast&l ...

  7. MAGIC XPA最新版本Magic xpa 2.4c Release Notes

    New Features, Feature Enhancements and Behavior ChangesSubforms – Behavior Change for Unsupported Ta ...

  8. 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 ...

  9. How Spring Boot Autoconfiguration Magic Works--转

    原文地址:https://dzone.com/articles/how-springboot-autoconfiguration-magic-works In my previous post &qu ...

  10. Magic CSS3 – 创建各种神奇的交互动画效果

    Magic CSS3 Animations 动画是一个独特的 CSS3 动画特效包,你可以自由地使用您的 Web 项目中.只需简单的在页面上引入 CSS 样式: magic.css 或者压缩版本 ma ...

随机推荐

  1. requests模块安装

    使用python写接口,必不可少的就是requests,所以事先要在python中安装requests     ​一.使用pip install安装(项目的命令行终端使用) 1.配置下载源地址路径(清 ...

  2. mac接入两根网线

    mac机接了USB扩展槽之后,扩展槽可以接入一根网线,机器自带一个网线口,这样就可以同时接入两根网线,为什么要这样做? 因为我所在的公司是分内外网的,研发的机器是内网环境,而打包机有时候需要联网,那么 ...

  3. 3D圆饼图,可修改颜色,图片等,具体见代码:

    组件代码: <template> <!-- 饼图 --> <div :id="histogramId" v-bind:style="{hei ...

  4. 书写自动智慧文本分类器的开发与应用:支持多分类、多标签分类、多层级分类和Kmeans聚类

    书写自动智慧文本分类器的开发与应用:支持多分类.多标签分类.多层级分类和Kmeans聚类 文本分类器,提供多种文本分类和聚类算法,支持句子和文档级的文本分类任务,支持二分类.多分类.多标签分类.多层级 ...

  5. 【七】强化学习、gym学习平台扩充,更好的玩转虚拟环境,关于mujoco、mujoco-py、baselines安装配置

    相关文章: [一]gym环境安装以及安装遇到的错误解决 [二]gym初次入门一学就会-简明教程 [三]gym简单画图 [四]gym搭建自己的环境,全网最详细版本,3分钟你就学会了! [五]gym搭建自 ...

  6. 守护进程(Python)

    #__author__:Kelvin #date:2020/5/10 11:37 import time from multiprocessing import Process def son1(): ...

  7. SpringBoot 多模块开发 笔记(一)

    多模块开发 简易版 dao 层 也可以说是 Mapper 层 web 层 将 controller 放在这一层 还有 统一返回类型 和 自定义异常 也在放在这里 启动类也放在这里 model 层 也就 ...

  8. 优化利器In-Memory开启和效果

    本文主要介绍Oracle In-Memory 选件,Oracle在12.1.0.2就已经推出了In-Memory这个选件,现在通常会建议所有使用19.8及之后版本的用户,有条件都要留给In-memor ...

  9. Linux--top命令解释

    top命令解释 1.1 系统运行时间和平均负载: top命令的顶部显示与uptime命令相似的输出 这些字段显示: 当前时间 系统已运行的时间 当前登录用户的数量 相应最近5.10和15分钟内的平均负 ...

  10. 【LGR-153-Div.2】梦熊联盟 8 月月赛 Ⅳ & Cfz Round 1 & 飞熊杯 #1

    [LGR-153-Div.2]梦熊联盟 8 月月赛 Ⅳ & Cfz Round 1 & 飞熊杯 #1 \(T1\) luogu P9577 「Cfz Round 1」Dead Cell ...