0% found this document useful (0 votes)
14 views11 pages

Python技术手册(Python in a Nutshell 2nd Edition)

Uploaded by

223323303
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views11 pages

Python技术手册(Python in a Nutshell 2nd Edition)

Uploaded by

223323303
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Python

1 2 3

(I)

10 10%

10 20 10 10% 10

7.5%

20 40 20 5%

40 60 40 3%

60 100 60 1.5%

100

100 1%

100 168

x y z

* C

c Very Beautiful!

9*9

9
10

11

12

101-200

13

153 153=1

14

90, 90=2*3*3*5

15

>=90 A 60-89

B 60 C

17

18

s=a + aa + aaa + aaaa + aa...a a

2+22+222+2222+22222( 5 )

19

6=1 2 3

1000

20

100

10 10

21
10

22

a,b,c x,y,z

a x c x,z

23

24

2/1 3/2 5/3 8/5 13/8 21/13... 20

25

1+2!+3!+...+20!

26

5!

27

28

5 4 2 4

3 2 2 2

10

29

30

5 12321

31
32

Press any key to change color, do you want to try it. Please hurry up!

33

gotoxy() clrscr()

34

35

36

100

37

10

38

3*3

39

40

41

static

42

auto

43

static

44

external

45

register

46
#define (1)

47

#define (2)
#include "stdio.h"
#define exchange(a,b) { \ /*
"\"*/
int t;\
t=a;\
a=b;\
b=t;\
}'

python

48

#define (3)

1.

2.
#define LAG >
#define SMA <
#define EQ ==
#include "stdio.h"
void main()
{
int i=10;
int j=20;
if(i LAG j)
printf("\40: %d larger than %d \n",i,j);
else if(i EQ j)
printf("\40: %d equal to %d \n",i,j);
else if(i SMA j)
printf("\40:%d smaller than %d \n",i,j);
else
printf("\40: No such value.\n");
}
python

49

#if #ifdef #ifndef

1.

2.
#include "stdio.h"
#define MAX
#define MAXIMUM(x,y) (x>y)?x:y
#define MINIMUM(x,y) (x>y)?y:x
void main()
{
int a=10,b=20;
#ifdef MAX
printf("\40: The larger one is %d\n",MAXIMUM(a,b));
#else
printf("\40: The lower one is %d\n",MINIMUM(a,b));
#endif
#ifndef MIN
printf("\40: The lower one is %d\n",MINIMUM(a,b));
#else
printf("\40: The larger one is %d\n",MAXIMUM(a,b));
#endif
#undef MAX
#ifdef MAX
printf("\40: The larger one is %d\n",MAXIMUM(a,b));
#else
printf("\40: The lower one is %d\n",MINIMUM(a,b));
#endif
#define MIN
#ifndef MIN
printf("\40: The lower one is %d\n",MINIMUM(a,b));
#else
printf("\40: The larger one is %d\n",MAXIMUM(a,b));
#endif
}

python lambda

50

51

&

52

53

54

a 4

55

56

circle

57

line

58

rectangle
59

60

1.

2.

#include "graphics.h"
#define LEFT 0
#define TOP 0
#define RIGHT 639
#define BOTTOM 479
#define LINES 400
#define MAXCOLOR 15
main()
{
int driver,mode,error;
int x1,y1;
int x2,y2;
int dx1,dy1,dx2,dy2,i=1;
int count=0;
int color=0;
driver=VGA;
mode=VGAHI;
initgraph(&driver,&mode,"");
x1=x2=y1=y2=10;
dx1=dy1=2;
dx2=dy2=3;
while(!kbhit())
{
line(x1,y1,x2,y2);
x1+=dx1;y1+=dy1;
x2+=dx2;y2+dy2;
if(x1<=LEFT||x1>=RIGHT)
dx1=-dx1;
if(y1<=TOP||y1>=BOTTOM)
dy1=-dy1;
if(x2<=LEFT||x2>=RIGHT)
dx2=-dx2;
if(y2<=TOP||y2>=BOTTOM)
dy2=-dy2;
if(++count>LINES)
{
setcolor(color);
color=(color>=MAXCOLOR)?0:++color;
}
}
closegraph();
}
61
10

62

putpixel
#include "stdio.h"
#include "graphics.h"
main()
{
int i,j,driver=VGA,mode=VGAHI;
initgraph(&driver,&mode,"");
setbkcolor(YELLOW);
for(i=50;i<=230;i+=20)
for(j=50;j<=230;j++)
putpixel(i,j,1);
for(j=50;j<=230;j+=20)
for(i=50;i<=230;i++)
putpixel(i,j,1);
}
63

ellipse

64

ellipse and rectangle

65

66

3 a,b,c

67

68

n m m m

69

n 1 3 3

70

main

71
input() output() 5

72

73

74

75

76

n 1/2+1/4+...+1/n , n

1/1+1/3+...+1/n ( )

77

78

79

80

81

809*??=800*??+9*??+1 ?? 8*?? 9*??

3 ?? 809*??

82

83

0 7

84
85

86

87

88

7 1 50

89

5, 10

90

if __name__ == '__main__':
M=5
a = [1,2,3,4,5]
i=0
j=M-1
while i < M:
a[i],a[j] = a[j],a[i]
print a
i += 1
j -= 1
for i in range(5):
print a[i]
91

92

93

94
4,

96

97

98

test

99

: A B, ,

You might also like