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. 【JS 逆向百例】无限debugger绕过,某政民互动数据逆向

    声明 本文章中所有内容仅供学习交流,抓包内容.敏感网址.数据接口均已做脱敏处理,严禁用于商业用途和非法用途,否则由此产生的一切后果均与作者无关,若有侵权,请联系我立即删除! 逆向目标 目标:某政务服务 ...

  2. STM32CubeMX教程26 FatFs 文件系统 - W25Q128读写

    1.准备材料 正点原子stm32f407探索者开发板V2.4 STM32CubeMX软件(Version 6.10.0) keil µVision5 IDE(MDK-Arm) ST-LINK/V2驱动 ...

  3. RestTemplate-postForObject详解、调用Https接口、源码解析,读懂这一篇文章就够了

    restTemplate 目录 restTemplate 1. 基本介绍 2. 常用方法分析及举例 2.1. get请求 2.2. post请求 3. springboot中使用restTemplat ...

  4. 设计模式学习-使用go实现中介者模式

    中介模式 定义 优点 缺点 适用范围 代码实现 参考 中介模式 定义 中介模式(Mediator):用一个中介对象来封装一系列的对象交互.中介者使个各对象不需要显示的相互引用,从而使其藕合松散,而且可 ...

  5. Solon 框架启动为什么特别快?

    思来想去!可能与 Solon 容器的独立设计有一定关系. 1.Solon 注解容器的运行特点 有什么注解要处理的(注解能力被规范成了四种),提前注册登记 全局只扫描一次,并在扫描过程中统一处理注解相关 ...

  6. 【学习日志】Java基本数据类型的自动装箱和拆箱

    // 测试代码 public static void main(String[] args) { Integer a = 1; Integer b = 2; Integer c = 3; Intege ...

  7. Prompt工程师指南[高阶篇]:对抗性Prompting、主动prompt、ReAct、GraphPrompts、Multimodal CoT Prompting等

    Prompt工程师指南[高阶篇]:对抗性Prompting.主动prompt.ReAct.GraphPrompts.Multimodal CoT Prompting等 1.对抗性 Prompting ...

  8. PBKDF2算法:保护密码安全的重要工具

    摘要:在当今的数字世界中,密码安全是至关重要的.为了保护用户密码免受未经授权的访问和破解,Password-Based Key Derivation Function 2 (PBKDF2)算法成为了一 ...

  9. 将实体光盘制作成光盘映像iso文件

    春节假期整理历史物件时发现一些书籍的光盘,虽然买了多年但一直没有看过,因为自己在用的电脑都没有光驱.正好老爸的电脑是带光驱的,想着趁过节把这些光盘的内容读取出来存在NAS上方便后续使用. 使用Ultr ...

  10. TStringList的IndexOfName

    IndexOfName这个方法用着很好,记录下,以后留意下 上个例子: procedure TForm1.Button1Click(Sender: TObject); var MyList: TStr ...