[pro 51]
题目:学习使用按位或 | 。
1.程序分析:0|0=0; 0|1=1; 1|0=1; 1|1=1
2.程序源代码:
'''
if __name__ == '__main__':
a = 077
b = a | 3
print 'a | b is %d' % b
b |= 7
print 'a | b is %d' % b
'''
[prgm 52]
题目:学习使用按位或 | 。
1.程序分析:0|0=0; 0|1=1; 1|0=1; 1|1=1
2.程序源代码:
'''
if __name__ == '__main__':
a = 077
b = a | 3
print 'a | b is %d' % b
b |= 7
print 'a | b is %d' % b
'''
【程序53】
题目:学习使用按位异或 ^ 。
1.程序分析:0^0=0; 0^1=1; 1^0=1; 1^1=0
2.程序源代码:
'''
if __name__ == '__main__':
a = 077
b = a ^ 3
print 'The a ^ 3 = %d' % b
b ^= 7
print 'The a ^ b = %d' % b
'''
【程序54】
题目:取一个整数a从右端开始的4~7位。
程序分析:可以这样考虑:
(1)先使a右移4位。
(2)设置一个低4位全为1,其余全为0的数。可用~(~0<<4)
(3)将上面二者进行&运算。
'''
if __name__ == '__main__':
a = int(raw_input('input a number:/n'))
b = a >> 4
c = ~(~0 << 4)
d = b & c
print '%o/t%o' %(a,d)
'''
【程序55】
题目:学习使用按位取反~。
1.程序分析:~0=1; ~1=0;
2.程序源代码:
如何查看复数的16进制数
'''
if __name__ == '__main__':
a = 234
b = ~a
print 'The a/'s 1 complement is %d' % b
a = ~a
print 'The a/'s 2 complement is %d' % a
'''
【程序56】
题目:画图,学用circle画圆形。
1.程序分析:
2.程序源代码:
#include "graphics.h"
main()
{
int driver,mode,i;
float j=1,k=1;
driver=VGA;mode=VGAHI;
initgraph(&driver,&mode,"");
setbkcolor(YELLOW);
for(i=0;i<=25;i++)
{
setcolor(8);
circle(310,250,k);
k=k+j;
j=j+0.3;
}
}
'''
if __name__ == '__main__':
from Tkinter import *
canvas = Canvas(width=800, height=600, bg='yellow')
canvas.pack(expand=YES, fill=BOTH)
k = 1
j = 1
for i in range(0,26):
canvas.create_oval(310 - k,250 - k,310 + k,250 + k, width=1)
k += j
j += 0.3
mainloop()
'''
【程序57】
题目:画图,学用line画直线。
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
from Tkinter import *
canvas = Canvas(width=300, height=300, bg='green')
canvas.pack(expand=YES, fill=BOTH)
x0 = 263
y0 = 263
y1 = 275
x1 = 275
for i in range(19):
canvas.create_line(x0,y0,x0,y1, width=1, fill='red')
x0 = x0 - 5
y0 = y0 - 5
x1 = x1 + 5
y1 = y1 + 5
x0 = 263
y1 = 275
y0 = 263
for i in range(21):
canvas.create_line(x0,y0,x0,y1,fill = 'red')
x0 += 5
y0 += 5
y1 += 5
mainloop()
'''
【程序58】
题目:画图,学用rectangle画方形。
1.程序分析:利用for循环控制100-999个数,每个数分解出个位,十位,百位。
2.程序源代码:
'''
if __name__ == '__main__':
from Tkinter import *
root = Tk()
root.title('Canvas')
canvas = Canvas(root,width = 400,height = 400,bg = 'yellow')
x0 = 263
y0 = 263
y1 = 275
x1 = 275
for i in range(19):
canvas.create_rectangle(x0,y0,x1,y1)
x0 -= 5
y0 -= 5
x1 += 5
y1 += 5
canvas.pack()
root.mainloop()
'''
[pro 59]
题目:画图,综合例子。
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
from Tkinter import *
canvas = Canvas(width = 300,height = 300,bg = 'green')
canvas.pack(expand = YES,fill = BOTH)
x0 = 150
y0 = 100
canvas.create_oval(x0 - 10,y0 - 10,x0 + 10,y0 + 10)
canvas.create_oval(x0 - 20,y0 - 20,x0 + 20,y0 + 20)
canvas.create_oval(x0 - 50,y0 - 50,x0 + 50,y0 + 50)
import math
B = 0.809
for i in range(16):
a = 2 * math.pi / 16 * i
x = math.ceil(x0 + 48 * math.cos(a))
y = math.ceil(y0 + 48 * math.sin(a) * B)
canvas.create_line(x0,y0,x,y,fill = 'red')
canvas.create_oval(x0 - 60,y0 - 60,x0 + 60,y0 + 60)
for k in range(501):
for i in range(17):
a = (2 * math.pi / 16) * i + (2 * math.pi / 180) * k
x = math.ceil(x0 + 48 * math.cos(a))
y = math.ceil(y0 + 48 + math.sin(a) * B)
canvas.create_line(x0,y0,x,y,fill = 'red')
for j in range(51):
a = (2 * math.pi / 16) * i + (2* math.pi / 180) * k - 1
x = math.ceil(x0 + 48 * math.cos(a))
y = math.ceil(y0 + 48 * math.sin(a) * B)
canvas.create_line(x0,y0,x,y,fill = 'red')
mainloop()
'''
【程序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行如下图)
1.程序分析:
'''
if __name__ == '__main__':
a = []
for i in range(10):
a.append([])
for j in range(10):
a[i].append(0)
for i in range(10):
a[i][0] = 1
a[i][i] = 1
for i in range(2,10):
for j in range(1,i):
a[i][j] = a[i - 1][j-1] + a[i - 1][j]
from sys import stdout
for i in range(10):
for j in range(i + 1):
stdout.write(a[i][j])
stdout.write(' ')
print
'''
【程序62】
题目:学习putpixel画点。
1.程序分析:
2.程序源代码:
#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);
}
'''
'''[pro63]
题目:画椭圆ellipse
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
from Tkinter import *
x = 360
y = 160
top = y - 30
bottom = y - 30
canvas = Canvas(width = 400,height = 600,bg = 'white')
for i in range(20):
canvas.create_oval(250 - top,250 - bottom,250 + top,250 + bottom)
top -= 5
bottom += 5
canvas.pack()
mainloop()
'''[pro64]
题目:利用ellipse and rectangle 画图。
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
from Tkinter import *
canvas = Canvas(width = 400,height = 600,bg = 'white')
left = 20
right = 50
top = 50
num = 15
for i in range(num):
canvas.create_oval(250 - right,250 - left,250 + right,250 + left)
canvas.create_oval(250 - 20,250 - top,250 + 20,250 + top)
canvas.create_rectangle(20 - 2 * i,20 - 2 * i,10 * (i + 2),10 * ( i + 2))
right += 5
left += 5
top += 10
canvas.pack()
mainloop()
'''
【程序65】
题目:一个最优美的图案。
1.程序分析:
2.程序源代码:
'''
import math
class PTS:
def __init__(self):
self.x = 0
self.y = 0
points = []
def LineToDemo():
from Tkinter import *
screenx = 400
screeny = 400
canvas = Canvas(width = screenx,height = screeny,bg = 'white')
AspectRatio = 0.85
MAXPTS = 15
h = screeny
w = screenx
xcenter = w / 2
ycenter = h / 2
radius = (h - 30) / (AspectRatio * 2) - 20
step = 360 / MAXPTS
angle = 0.0
for i in range(MAXPTS):
rads = angle * math.pi / 180.0
p = PTS()
p.x = xcenter + int(math.cos(rads) * radius)
p.y = ycenter - int(math.sin(rads) * radius * AspectRatio)
angle += step
points.append(p)
canvas.create_oval(xcenter - radius,ycenter - radius,
xcenter + radius,ycenter + radius)
for i in range(MAXPTS):
for j in range(i,MAXPTS):
canvas.create_line(points[i].x,points[i].y,points[j].x,points[j].y)
canvas.pack()
mainloop()
if __name__ == '__main__':
LineToDemo()
'''
【程序66】
题目:输入3个数a,b,c,按大小顺序输出。
1.程序分析:利用指针方法。
2.程序源代码:
'''
if __name__ == '__main__':
n1 = int(raw_input('n1 = :/n'))
n2 = int(raw_input('n2 = :/n'))
n3 = int(raw_input('n3 = :/n'))
def swap(p1,p2):
return p2,p1
if n1 > n2 : n1,n2 = swap(n1,n2)
if n1 > n3 : n1,n3 = swap(n1,n3)
if n2 > n3 : n2,n3 = swap(n2,n3)
print n1,n2,n3
'''
[pro67]
题目:输入数组,最大的与第一个元素交换,最小的与最后一个元素交换,输出数组。
1.程序分析:谭浩强的书中答案有问题。
2.程序源代码:
'''
def inp(numbers):
for i in range(9):
numbers.append(int(raw_input('input a number:/n')))
numbers.append(int(raw_input('input a number:/n')))
p = 0
def max_min(array):
max = min = 0
for i in range(1,len(array) - 1):
p = i
if array[p] > array[max] : max = p
elif array[p] < array[min] : min = p
k = max
l = min
array[0],array[l] = array[l],array[0]
array[9],array[k] = array[k],array[9]
def outp(numbers):
for i in range(len(numbers)):
print numbers[i]
if __name__ == '__main__':
array = []
inp(array)
max_min(array)
outp(array)
'''
【程序68】
题目:有n个整数,使其前面各数顺序向后移m个位置,最后m个数变成最前面的m个数
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
n = int(raw_input('the total number is:/n'))
m = int(raw_input('back m:/n'))
def move(array,n,m):
array_end = array[n - 1]
for i in range(n - 1,-1,- 1):
array[i] = array[i - 1]
array[0] = array_end
m -= 1
if m > 0:move(array,n,m)
number = []
for i in range(n):
number.append(int(raw_input('input a number:/n')))
print 'orignal number:',number
move(number,n,m)
print 'after moved:',number
'''
【程序69】
题目:有n个人围成一圈,顺序排号。从第一个人开始报数(从1到3报数),凡报到3的
人退出
圈子,问最后留下的是原来第几号的那位。
1. 程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
nmax = 50
n = int(raw_input('please input the total of numbers:'))
num = []
for i in range(n):
num.append(i + 1)
i = 0
k = 0
m = 0
while m < n - 1:
if num[i] != 0 : k += 1
if k == 3:
num[i] = 0
k = 0
m += 0
i += 1
if i == n : i = 0
i = 0
while num[i] == 0: i += 1
print num[i]
'''
[pro 70]
题目:写一个函数,求一个字符串的长度,在main函数中输入字符串,并输出其长度。
1.程序分析:
2.程序源代码
就这样吧
'''
if __name__ == '__main__':
s = raw_input('please input a string:/n')
print 'the string has %d characters.' % len(s)
'''
【程序71】
题目:编写input()和output()函数输入,输出5个学生的数据记录。
1.程序分析:
2.程序源代码:
使用list来模拟结构(不使用class)
stu = [string,string,list]
'''
N = 3
#stu
# num : string
# name : string
# score[4]: list
student = []
for i in range(5):
student.append(['','',[]])
def input_stu(stu):
for i in range(N):
stu[i][0] = raw_input('input student num:/n')
stu[i][1] = raw_input('input student name:/n')
for j in range(3):
stu[i][2].append(int(raw_input('score:/n')))
def output_stu(stu):
for i in range(N):
print '%-6s%-10s' % ( stu[i][0],stu[i][1] )
for j in range(3):
print '%-8d' % stu[i][2][j]
if __name__ == '__main__':
input_stu(student)
print student
output_stu(student)
'''
【程序72】
题目:创建一个链表。
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
ptr = []
for i in range(5):
num = int(raw_input('please input a number:/n'))
ptr.append(num)
print ptr
'''
[pro73]
题目:反向输出一个链表。
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
ptr = []
for i in range(5):
num = int(raw_input('please input a number:/n'))
ptr.append(num)
print ptr
ptr.reverse()
print ptr
'''
【程序74】
题目:连接两个链表。
1.程序分析:
2.程序源代码:
代码上好像只有,列表排序
'''
if __name__ == '__main__':
arr1 = (3,12,8,9,11)
ptr = list(arr1)
print ptr
ptr.sort()
print ptr
'''
【程序75】
题目:放松一下,算一道简单的题目。
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
for i in range(5):
n = 0
if i != 1: n += 1
if i == 3: n += 1
if i == 4: n += 1
if i != 4: n += 1
if n == 3: print 64 + i
'''
【程序76】
题目:编写一个函数,输入n为偶数时,调用函数求1/2+1/4+...+1/n,当输入n为奇数时,
调用函数
1/1+1/3+...+1/n(利用指针函数)
1.程序分析:
2.程序源代码:
'''
def peven(n):
i = 0
s = 0.0
for i in range(2,n + 1,2):
s += 1.0 / i
return s
def podd(n):
s = 0.0
for i in range(1, n + 1,2):
s += 1 / i
return s
def dcall(fp,n):
s = fp(n)
return s
if __name__ == '__main__':
n = int(raw_input('input a number:/n'))
if n % 2 == 0:
sum = dcall(peven,n)
else:
sum = dcall(podd,n)
print sum
'''
【程序77】
题目:填空练习(指向指针的指针)
1.程序分析:
2.程序源代码:
main()
{
char *s[]={"man","woman","girl","boy","sister"};
char **q;
int k;
for(k=0;k<5;k++)
{;/*?aà?ì?D′ê2?′ó???*/
printf("%s/n",*q);
}
}
'''
if __name__ == '__main__':
s = ["man","woman","girl","boy","sister"]
for i in range(len(s)):
print s[i]
'''
【程序78】
题目:找到年龄最大的人,并输出。请找出程序中有什么问题。
1.程序分析:
2.程序源代码
'''
if __name__ == '__main__':
person = {"li":18,"wang":50,"zhang":20,"sun":22}
m = 'li'
for key in person.keys():
if person[m] < person[key]:
m = key
print '%s,%d' % (m,person[m])
'''
【程序79】
题目:字符串排序。
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
str1 = raw_input('input string:/n')
str2 = raw_input('input string:/n')
str3 = raw_input('input string:/n')
print str1,str2,str3
if str1 > str2 : str1,str2 = str2,str1
if str1 > str3 : str1,str3 = str3,str1
if str2 > str3 : str2,str3 = str3,str2
print 'after being sorted.'
print str1,str2,str3
'''
【程序80】
题目:海滩上有一堆桃子,五只猴子来分。第一只猴子把这堆桃子凭据分为五份,多了一
个,这只
猴子把多的一个扔入海中,拿走了一份。第二只猴子把剩下的桃子又平均分成五
份,又多了
一个,它同样把多的一个扔入海中,拿走了一份,第三、第四、第五只猴子都是这
样做的,
问海滩上原来最少有多少个桃子?
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
for i in range(4,10000,4):
count = 0
m = i
for k in range(5):
j = i / 4 * 5 + 1
i = j
if j % 4 == 0:
count += 1
else:
break
i = m
if count == 4:
print count
break
'''
【程序81】
题目:809*??=800*??+9*??+1 其中??代表的两位数,8*??的结果为两位数,9*??的结果
为3位数。求??代表的两位数,及809*??后的结果。
1.程序分析:
2.程序源代码
这个程序实在是奇怪
0 = 1 :(
就写个程序而已,不去追究了
'''
a = 809
for i in range(10,100):
b = i * a + 1
if b >= 1000 and b <= 10000 and 8 * i < 100 and 9 * i >= 100:
print b,'/',i,' = 809 * ',i,' + ', b % i
'''
【程序82】
题目:八进制转换为十进制
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
n = 0
p = raw_input('input a octal number:/n')
for i in range(len(p)):
n = n * 8 + ord(p[i]) - ord('0')
print n
'''
【程序83】
题目:求0—7所能组成的奇数个数。
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
sum = 4
s = 4
for j in range(2,9):
print sum
if j <= 2:
s *= 7
else:
s *= 8
sum += s
print 'sum = %d' % sum
'''
【程序84】
题目:一个偶数总能表示为两个素数之和。
1.程序分析:
2.程序源代码:
此代码有问题,待修改
'''
import math
if __name__ == '__main__':
a = int(raw_input('input an odd number:/n'))
d = 0
c = 2
for b in range(3,a / 2 + 1,2):
m = 0
for c in range(2,int(math.sqrt(b)) + 1):
if b % c == 0 :
m = c
break
if m > math.sqrt(b):
d = a - b
else:
break
for c in range(2,int(math.sqrt(d)) + 1):
if d % c == 0:
m = c
break
if m > math.sqrt(d):
print '%d = %d + %d' % (a,b,d)
'''
【程序85】
题目:判断一个素数能被几个9整除
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
zi = int(raw_input('input a number:/n'))
n1 = 1
c9 = 1
m9 = 9
sum = 9
while n1 != 0:
if sum % zi == 0:
n1 = 0
else:
m9 *= 10
sum += m9
c9 += 1
print '%d can be divided by %d 9' % (sum,c9)
'''
【程序86】
题目:两个字符串连接程序
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
a = "acegikm"
b = "bdfhjlnpq"
# 连接字符串
c = a + b
print c
'''
【程序87】
题目:回答结果(结构体变量传递)
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
class student:
x = 0
c = 0
def f(stu):
stu.x = 20
stu.c = 'c'
a= student()
a.x = 3
a.c = 'a'
f(a)
print a.x,a.c
'''
【程序88】
题目:读取7个数(1—50)的整数值,每读取一个值,程序打印出该值个数的*。
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
n = 1
while n <= 7:
a = int(raw_input('input a number:/n'))
while a < 1 or a > 50:
a = int(raw_input('input a number:/n'))
print a * '*'
n += 1
'''
【程序89】
题目:某个公司采用公用电话传递数据,数据是四位的整数,在传递过程中是加密的,加
密规则如下:
每位数字都加上5,然后用和除以10的余数代替该数字,再将第一位和第四位交换,
第二位和第三位交换。
1.程序分析:
2.程序源代码:
'''
from sys import stdout
if __name__ == '__main__':
a = int(raw_input('input a number:/n'))
aa = []
aa.append(a % 10)
aa.append(a % 100 / 10)
aa.append(a % 1000 / 100)
aa.append(a / 1000)
for i in range(4):
aa[i] += 5
aa[i] %= 10
for i in range(2):
aa[i],aa[3 - i] = aa[3 - i],aa[i]
for i in range(3,-1,-1):
stdout.write(aa[i])
'''
【程序90】
题目:专升本一题,读结果。
1.程序分析:
2.程序源代码:
'''
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】
题目:时间函数举例1
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
import time
print time.ctime(time.time())
print time.asctime(time.localtime(time.time()))
print time.asctime(time.gmtime(time.time()))
'''
【程序92】
题目:时间函数举例2
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
import time
start = time.time()
for i in range(3000):
print i
end = time.time()
print end - start
'''
【程序93】
题目:时间函数举例3
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
import time
start = time.clock()
for i in range(10000):
print i
end = time.clock()
print 'different is %6.3f' % (end - start)
'''
【程序94】
题目:时间函数举例4,一个猜数游戏,判断一个人反应快慢。(版主初学时编的)
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
import time
import random
play_it = raw_input('do you want to play it.(/'y/' or /'n/')')
while play_it == 'y':
c = raw_input('input a character:/n')
i = random.randint(0,2**32) % 100
print 'please input number you guess:/n'
start = time.clock()
a = time.time()
guess = int(raw_input('input your guess:/n'))
while guess != i:
if guess > i:
print 'please input a little smaller'
guess = int(raw_input('input your guess:/n'))
else:
print 'please input a little bigger'
guess = int(raw_input('input your guess:/n'))
end = time.clock()
b = time.time()
var = (end - start) / 18.2
print var
# print 'It took you %6.3 seconds' % time.difftime(b,a))
if var < 15:
print 'you are very clever!'
elif var < 25:
print 'you are normal!'
else:
print 'you are stupid!'
print 'Congradulations'
print 'The number you guess is %d' % i
play_it = raw_input('do you want to play it.')
'''
【程序96】
题目:计算字符串中子串出现的次数
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
str1 = raw_input('input a string:/n')
str2 = raw_input('input a sub string:/n')
ncount = str1.count(str2)
print ncount
'''
【程序97】
题目:从键盘输入一些字符,逐个把它们送到磁盘上去,直到输入一个#为止。
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
from sys import stdout
filename = raw_input('input a file name:/n')
fp = open(filename,"w")
ch = raw_input('input string:/n')
while ch != '#':
fp.write(ch)
stdout.write(ch)
ch = raw_input('')
fp.close()
'''
【程序98】
题目:从键盘输入一个字符串,将小写字母全部转换成大写字母,然后输出到一个磁盘文
件“test”中保存。
输入的字符串以!结束。
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
fp = open('test.txt','w')
string = raw_input('please input a string:/n')
string = string.upper()
fp.write(string)
fp = open('test.txt','r')
print fp.read()
fp.close()
'''
程序99】
题目:有两个磁盘文件A和B,各存放一行字母,要求把这两个文件中的信息合并(按字母顺序
排列),
输出到一个新文件C中.
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
import string
fp = open('JCP099.py')
a = fp.read()
fp.close()
fp = open('JCP098.py')
b = fp.read()
fp.close()
fp = open('C.txt','w')
l = list(a + b)
l.sort()
s = ''
s = s.join(l)
fp.write(s)
fp.close()
题目:学习使用按位或 | 。
1.程序分析:0|0=0; 0|1=1; 1|0=1; 1|1=1
2.程序源代码:
'''
if __name__ == '__main__':
a = 077
b = a | 3
print 'a | b is %d' % b
b |= 7
print 'a | b is %d' % b
'''
[prgm 52]
题目:学习使用按位或 | 。
1.程序分析:0|0=0; 0|1=1; 1|0=1; 1|1=1
2.程序源代码:
'''
if __name__ == '__main__':
a = 077
b = a | 3
print 'a | b is %d' % b
b |= 7
print 'a | b is %d' % b
'''
【程序53】
题目:学习使用按位异或 ^ 。
1.程序分析:0^0=0; 0^1=1; 1^0=1; 1^1=0
2.程序源代码:
'''
if __name__ == '__main__':
a = 077
b = a ^ 3
print 'The a ^ 3 = %d' % b
b ^= 7
print 'The a ^ b = %d' % b
'''
【程序54】
题目:取一个整数a从右端开始的4~7位。
程序分析:可以这样考虑:
(1)先使a右移4位。
(2)设置一个低4位全为1,其余全为0的数。可用~(~0<<4)
(3)将上面二者进行&运算。
'''
if __name__ == '__main__':
a = int(raw_input('input a number:/n'))
b = a >> 4
c = ~(~0 << 4)
d = b & c
print '%o/t%o' %(a,d)
'''
【程序55】
题目:学习使用按位取反~。
1.程序分析:~0=1; ~1=0;
2.程序源代码:
如何查看复数的16进制数
'''
if __name__ == '__main__':
a = 234
b = ~a
print 'The a/'s 1 complement is %d' % b
a = ~a
print 'The a/'s 2 complement is %d' % a
'''
【程序56】
题目:画图,学用circle画圆形。
1.程序分析:
2.程序源代码:
#include "graphics.h"
main()
{
int driver,mode,i;
float j=1,k=1;
driver=VGA;mode=VGAHI;
initgraph(&driver,&mode,"");
setbkcolor(YELLOW);
for(i=0;i<=25;i++)
{
setcolor(8);
circle(310,250,k);
k=k+j;
j=j+0.3;
}
}
'''
if __name__ == '__main__':
from Tkinter import *
canvas = Canvas(width=800, height=600, bg='yellow')
canvas.pack(expand=YES, fill=BOTH)
k = 1
j = 1
for i in range(0,26):
canvas.create_oval(310 - k,250 - k,310 + k,250 + k, width=1)
k += j
j += 0.3
mainloop()
'''
【程序57】
题目:画图,学用line画直线。
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
from Tkinter import *
canvas = Canvas(width=300, height=300, bg='green')
canvas.pack(expand=YES, fill=BOTH)
x0 = 263
y0 = 263
y1 = 275
x1 = 275
for i in range(19):
canvas.create_line(x0,y0,x0,y1, width=1, fill='red')
x0 = x0 - 5
y0 = y0 - 5
x1 = x1 + 5
y1 = y1 + 5
x0 = 263
y1 = 275
y0 = 263
for i in range(21):
canvas.create_line(x0,y0,x0,y1,fill = 'red')
x0 += 5
y0 += 5
y1 += 5
mainloop()
'''
【程序58】
题目:画图,学用rectangle画方形。
1.程序分析:利用for循环控制100-999个数,每个数分解出个位,十位,百位。
2.程序源代码:
'''
if __name__ == '__main__':
from Tkinter import *
root = Tk()
root.title('Canvas')
canvas = Canvas(root,width = 400,height = 400,bg = 'yellow')
x0 = 263
y0 = 263
y1 = 275
x1 = 275
for i in range(19):
canvas.create_rectangle(x0,y0,x1,y1)
x0 -= 5
y0 -= 5
x1 += 5
y1 += 5
canvas.pack()
root.mainloop()
'''
[pro 59]
题目:画图,综合例子。
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
from Tkinter import *
canvas = Canvas(width = 300,height = 300,bg = 'green')
canvas.pack(expand = YES,fill = BOTH)
x0 = 150
y0 = 100
canvas.create_oval(x0 - 10,y0 - 10,x0 + 10,y0 + 10)
canvas.create_oval(x0 - 20,y0 - 20,x0 + 20,y0 + 20)
canvas.create_oval(x0 - 50,y0 - 50,x0 + 50,y0 + 50)
import math
B = 0.809
for i in range(16):
a = 2 * math.pi / 16 * i
x = math.ceil(x0 + 48 * math.cos(a))
y = math.ceil(y0 + 48 * math.sin(a) * B)
canvas.create_line(x0,y0,x,y,fill = 'red')
canvas.create_oval(x0 - 60,y0 - 60,x0 + 60,y0 + 60)
for k in range(501):
for i in range(17):
a = (2 * math.pi / 16) * i + (2 * math.pi / 180) * k
x = math.ceil(x0 + 48 * math.cos(a))
y = math.ceil(y0 + 48 + math.sin(a) * B)
canvas.create_line(x0,y0,x,y,fill = 'red')
for j in range(51):
a = (2 * math.pi / 16) * i + (2* math.pi / 180) * k - 1
x = math.ceil(x0 + 48 * math.cos(a))
y = math.ceil(y0 + 48 * math.sin(a) * B)
canvas.create_line(x0,y0,x,y,fill = 'red')
mainloop()
'''
【程序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行如下图)
1.程序分析:
'''
if __name__ == '__main__':
a = []
for i in range(10):
a.append([])
for j in range(10):
a[i].append(0)
for i in range(10):
a[i][0] = 1
a[i][i] = 1
for i in range(2,10):
for j in range(1,i):
a[i][j] = a[i - 1][j-1] + a[i - 1][j]
from sys import stdout
for i in range(10):
for j in range(i + 1):
stdout.write(a[i][j])
stdout.write(' ')
'''
【程序62】
题目:学习putpixel画点。
1.程序分析:
2.程序源代码:
#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);
}
'''
'''[pro63]
题目:画椭圆ellipse
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
from Tkinter import *
x = 360
y = 160
top = y - 30
bottom = y - 30
canvas = Canvas(width = 400,height = 600,bg = 'white')
for i in range(20):
canvas.create_oval(250 - top,250 - bottom,250 + top,250 + bottom)
top -= 5
bottom += 5
canvas.pack()
mainloop()
'''[pro64]
题目:利用ellipse and rectangle 画图。
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
from Tkinter import *
canvas = Canvas(width = 400,height = 600,bg = 'white')
left = 20
right = 50
top = 50
num = 15
for i in range(num):
canvas.create_oval(250 - right,250 - left,250 + right,250 + left)
canvas.create_oval(250 - 20,250 - top,250 + 20,250 + top)
canvas.create_rectangle(20 - 2 * i,20 - 2 * i,10 * (i + 2),10 * ( i + 2))
right += 5
left += 5
top += 10
canvas.pack()
mainloop()
'''
【程序65】
题目:一个最优美的图案。
1.程序分析:
2.程序源代码:
'''
import math
class PTS:
def __init__(self):
self.x = 0
self.y = 0
points = []
def LineToDemo():
from Tkinter import *
screenx = 400
screeny = 400
canvas = Canvas(width = screenx,height = screeny,bg = 'white')
AspectRatio = 0.85
MAXPTS = 15
h = screeny
w = screenx
xcenter = w / 2
ycenter = h / 2
radius = (h - 30) / (AspectRatio * 2) - 20
step = 360 / MAXPTS
angle = 0.0
for i in range(MAXPTS):
rads = angle * math.pi / 180.0
p = PTS()
p.x = xcenter + int(math.cos(rads) * radius)
p.y = ycenter - int(math.sin(rads) * radius * AspectRatio)
angle += step
points.append(p)
canvas.create_oval(xcenter - radius,ycenter - radius,
xcenter + radius,ycenter + radius)
for i in range(MAXPTS):
for j in range(i,MAXPTS):
canvas.create_line(points[i].x,points[i].y,points[j].x,points[j].y)
canvas.pack()
mainloop()
if __name__ == '__main__':
LineToDemo()
'''
【程序66】
题目:输入3个数a,b,c,按大小顺序输出。
1.程序分析:利用指针方法。
2.程序源代码:
'''
if __name__ == '__main__':
n1 = int(raw_input('n1 = :/n'))
n2 = int(raw_input('n2 = :/n'))
n3 = int(raw_input('n3 = :/n'))
def swap(p1,p2):
return p2,p1
if n1 > n2 : n1,n2 = swap(n1,n2)
if n1 > n3 : n1,n3 = swap(n1,n3)
if n2 > n3 : n2,n3 = swap(n2,n3)
print n1,n2,n3
'''
[pro67]
题目:输入数组,最大的与第一个元素交换,最小的与最后一个元素交换,输出数组。
1.程序分析:谭浩强的书中答案有问题。
2.程序源代码:
'''
def inp(numbers):
for i in range(9):
numbers.append(int(raw_input('input a number:/n')))
numbers.append(int(raw_input('input a number:/n')))
p = 0
def max_min(array):
max = min = 0
for i in range(1,len(array) - 1):
p = i
if array[p] > array[max] : max = p
elif array[p] < array[min] : min = p
k = max
l = min
array[0],array[l] = array[l],array[0]
array[9],array[k] = array[k],array[9]
def outp(numbers):
for i in range(len(numbers)):
print numbers[i]
if __name__ == '__main__':
array = []
inp(array)
max_min(array)
outp(array)
'''
【程序68】
题目:有n个整数,使其前面各数顺序向后移m个位置,最后m个数变成最前面的m个数
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
n = int(raw_input('the total number is:/n'))
m = int(raw_input('back m:/n'))
def move(array,n,m):
array_end = array[n - 1]
for i in range(n - 1,-1,- 1):
array[i] = array[i - 1]
array[0] = array_end
m -= 1
if m > 0:move(array,n,m)
number = []
for i in range(n):
number.append(int(raw_input('input a number:/n')))
print 'orignal number:',number
move(number,n,m)
print 'after moved:',number
'''
【程序69】
题目:有n个人围成一圈,顺序排号。从第一个人开始报数(从1到3报数),凡报到3的
人退出
圈子,问最后留下的是原来第几号的那位。
1. 程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
nmax = 50
n = int(raw_input('please input the total of numbers:'))
num = []
for i in range(n):
num.append(i + 1)
i = 0
k = 0
m = 0
while m < n - 1:
if num[i] != 0 : k += 1
if k == 3:
num[i] = 0
k = 0
m += 0
i += 1
if i == n : i = 0
i = 0
while num[i] == 0: i += 1
print num[i]
'''
[pro 70]
题目:写一个函数,求一个字符串的长度,在main函数中输入字符串,并输出其长度。
1.程序分析:
2.程序源代码
就这样吧
'''
if __name__ == '__main__':
s = raw_input('please input a string:/n')
print 'the string has %d characters.' % len(s)
'''
【程序71】
题目:编写input()和output()函数输入,输出5个学生的数据记录。
1.程序分析:
2.程序源代码:
使用list来模拟结构(不使用class)
stu = [string,string,list]
'''
N = 3
#stu
# num : string
# name : string
# score[4]: list
student = []
for i in range(5):
student.append(['','',[]])
def input_stu(stu):
for i in range(N):
stu[i][0] = raw_input('input student num:/n')
stu[i][1] = raw_input('input student name:/n')
for j in range(3):
stu[i][2].append(int(raw_input('score:/n')))
def output_stu(stu):
for i in range(N):
print '%-6s%-10s' % ( stu[i][0],stu[i][1] )
for j in range(3):
print '%-8d' % stu[i][2][j]
if __name__ == '__main__':
input_stu(student)
print student
output_stu(student)
'''
【程序72】
题目:创建一个链表。
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
ptr = []
for i in range(5):
num = int(raw_input('please input a number:/n'))
ptr.append(num)
print ptr
'''
[pro73]
题目:反向输出一个链表。
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
ptr = []
for i in range(5):
num = int(raw_input('please input a number:/n'))
ptr.append(num)
print ptr
ptr.reverse()
print ptr
'''
【程序74】
题目:连接两个链表。
1.程序分析:
2.程序源代码:
代码上好像只有,列表排序
'''
if __name__ == '__main__':
arr1 = (3,12,8,9,11)
ptr = list(arr1)
print ptr
ptr.sort()
print ptr
'''
【程序75】
题目:放松一下,算一道简单的题目。
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
for i in range(5):
n = 0
if i != 1: n += 1
if i == 3: n += 1
if i == 4: n += 1
if i != 4: n += 1
if n == 3: print 64 + i
'''
【程序76】
题目:编写一个函数,输入n为偶数时,调用函数求1/2+1/4+...+1/n,当输入n为奇数时,
调用函数
1/1+1/3+...+1/n(利用指针函数)
1.程序分析:
2.程序源代码:
'''
def peven(n):
i = 0
s = 0.0
for i in range(2,n + 1,2):
s += 1.0 / i
return s
def podd(n):
s = 0.0
for i in range(1, n + 1,2):
s += 1 / i
return s
def dcall(fp,n):
s = fp(n)
return s
if __name__ == '__main__':
n = int(raw_input('input a number:/n'))
if n % 2 == 0:
sum = dcall(peven,n)
else:
sum = dcall(podd,n)
print sum
'''
【程序77】
题目:填空练习(指向指针的指针)
1.程序分析:
2.程序源代码:
main()
{
char *s[]={"man","woman","girl","boy","sister"};
char **q;
int k;
for(k=0;k<5;k++)
{;/*?aà?ì?D′ê2?′ó???*/
printf("%s/n",*q);
}
}
'''
if __name__ == '__main__':
s = ["man","woman","girl","boy","sister"]
for i in range(len(s)):
print s[i]
'''
【程序78】
题目:找到年龄最大的人,并输出。请找出程序中有什么问题。
1.程序分析:
2.程序源代码
'''
if __name__ == '__main__':
person = {"li":18,"wang":50,"zhang":20,"sun":22}
m = 'li'
for key in person.keys():
if person[m] < person[key]:
m = key
print '%s,%d' % (m,person[m])
'''
【程序79】
题目:字符串排序。
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
str1 = raw_input('input string:/n')
str2 = raw_input('input string:/n')
str3 = raw_input('input string:/n')
print str1,str2,str3
if str1 > str2 : str1,str2 = str2,str1
if str1 > str3 : str1,str3 = str3,str1
if str2 > str3 : str2,str3 = str3,str2
print 'after being sorted.'
print str1,str2,str3
'''
【程序80】
题目:海滩上有一堆桃子,五只猴子来分。第一只猴子把这堆桃子凭据分为五份,多了一
个,这只
猴子把多的一个扔入海中,拿走了一份。第二只猴子把剩下的桃子又平均分成五
份,又多了
一个,它同样把多的一个扔入海中,拿走了一份,第三、第四、第五只猴子都是这
样做的,
问海滩上原来最少有多少个桃子?
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
for i in range(4,10000,4):
count = 0
m = i
for k in range(5):
j = i / 4 * 5 + 1
i = j
if j % 4 == 0:
count += 1
else:
break
i = m
if count == 4:
print count
break
'''
【程序81】
题目:809*??=800*??+9*??+1 其中??代表的两位数,8*??的结果为两位数,9*??的结果
为3位数。求??代表的两位数,及809*??后的结果。
1.程序分析:
2.程序源代码
这个程序实在是奇怪
0 = 1 :(
就写个程序而已,不去追究了
'''
a = 809
for i in range(10,100):
b = i * a + 1
if b >= 1000 and b <= 10000 and 8 * i < 100 and 9 * i >= 100:
print b,'/',i,' = 809 * ',i,' + ', b % i
'''
【程序82】
题目:八进制转换为十进制
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
n = 0
p = raw_input('input a octal number:/n')
for i in range(len(p)):
n = n * 8 + ord(p[i]) - ord('0')
print n
'''
【程序83】
题目:求0—7所能组成的奇数个数。
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
sum = 4
s = 4
for j in range(2,9):
print sum
if j <= 2:
s *= 7
else:
s *= 8
sum += s
print 'sum = %d' % sum
'''
【程序84】
题目:一个偶数总能表示为两个素数之和。
1.程序分析:
2.程序源代码:
此代码有问题,待修改
'''
import math
if __name__ == '__main__':
a = int(raw_input('input an odd number:/n'))
d = 0
c = 2
for b in range(3,a / 2 + 1,2):
m = 0
for c in range(2,int(math.sqrt(b)) + 1):
if b % c == 0 :
m = c
break
if m > math.sqrt(b):
d = a - b
else:
break
for c in range(2,int(math.sqrt(d)) + 1):
if d % c == 0:
m = c
break
if m > math.sqrt(d):
print '%d = %d + %d' % (a,b,d)
'''
【程序85】
题目:判断一个素数能被几个9整除
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
zi = int(raw_input('input a number:/n'))
n1 = 1
c9 = 1
m9 = 9
sum = 9
while n1 != 0:
if sum % zi == 0:
n1 = 0
else:
m9 *= 10
sum += m9
c9 += 1
print '%d can be divided by %d 9' % (sum,c9)
'''
【程序86】
题目:两个字符串连接程序
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
a = "acegikm"
b = "bdfhjlnpq"
# 连接字符串
c = a + b
print c
'''
【程序87】
题目:回答结果(结构体变量传递)
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
class student:
x = 0
c = 0
def f(stu):
stu.x = 20
stu.c = 'c'
a= student()
a.x = 3
a.c = 'a'
f(a)
print a.x,a.c
'''
【程序88】
题目:读取7个数(1—50)的整数值,每读取一个值,程序打印出该值个数的*。
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
n = 1
while n <= 7:
a = int(raw_input('input a number:/n'))
while a < 1 or a > 50:
a = int(raw_input('input a number:/n'))
print a * '*'
n += 1
'''
【程序89】
题目:某个公司采用公用电话传递数据,数据是四位的整数,在传递过程中是加密的,加
密规则如下:
每位数字都加上5,然后用和除以10的余数代替该数字,再将第一位和第四位交换,
第二位和第三位交换。
1.程序分析:
2.程序源代码:
'''
from sys import stdout
if __name__ == '__main__':
a = int(raw_input('input a number:/n'))
aa = []
aa.append(a % 10)
aa.append(a % 100 / 10)
aa.append(a % 1000 / 100)
aa.append(a / 1000)
for i in range(4):
aa[i] += 5
aa[i] %= 10
for i in range(2):
aa[i],aa[3 - i] = aa[3 - i],aa[i]
for i in range(3,-1,-1):
stdout.write(aa[i])
'''
【程序90】
题目:专升本一题,读结果。
1.程序分析:
2.程序源代码:
'''
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】
题目:时间函数举例1
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
import time
print time.ctime(time.time())
print time.asctime(time.localtime(time.time()))
print time.asctime(time.gmtime(time.time()))
'''
【程序92】
题目:时间函数举例2
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
import time
start = time.time()
for i in range(3000):
print i
end = time.time()
print end - start
'''
【程序93】
题目:时间函数举例3
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
import time
start = time.clock()
for i in range(10000):
print i
end = time.clock()
print 'different is %6.3f' % (end - start)
'''
【程序94】
题目:时间函数举例4,一个猜数游戏,判断一个人反应快慢。(版主初学时编的)
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
import time
import random
play_it = raw_input('do you want to play it.(/'y/' or /'n/')')
while play_it == 'y':
c = raw_input('input a character:/n')
i = random.randint(0,2**32) % 100
print 'please input number you guess:/n'
start = time.clock()
a = time.time()
guess = int(raw_input('input your guess:/n'))
while guess != i:
if guess > i:
print 'please input a little smaller'
guess = int(raw_input('input your guess:/n'))
else:
print 'please input a little bigger'
guess = int(raw_input('input your guess:/n'))
end = time.clock()
b = time.time()
var = (end - start) / 18.2
print var
# print 'It took you %6.3 seconds' % time.difftime(b,a))
if var < 15:
print 'you are very clever!'
elif var < 25:
print 'you are normal!'
else:
print 'you are stupid!'
print 'Congradulations'
print 'The number you guess is %d' % i
play_it = raw_input('do you want to play it.')
'''
【程序96】
题目:计算字符串中子串出现的次数
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
str1 = raw_input('input a string:/n')
str2 = raw_input('input a sub string:/n')
ncount = str1.count(str2)
print ncount
'''
【程序97】
题目:从键盘输入一些字符,逐个把它们送到磁盘上去,直到输入一个#为止。
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
from sys import stdout
filename = raw_input('input a file name:/n')
fp = open(filename,"w")
ch = raw_input('input string:/n')
while ch != '#':
fp.write(ch)
stdout.write(ch)
ch = raw_input('')
fp.close()
'''
【程序98】
题目:从键盘输入一个字符串,将小写字母全部转换成大写字母,然后输出到一个磁盘文
件“test”中保存。
输入的字符串以!结束。
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
fp = open('test.txt','w')
string = raw_input('please input a string:/n')
string = string.upper()
fp.write(string)
fp = open('test.txt','r')
print fp.read()
fp.close()
'''
程序99】
题目:有两个磁盘文件A和B,各存放一行字母,要求把这两个文件中的信息合并(按字母顺序
排列),
输出到一个新文件C中.
1.程序分析:
2.程序源代码:
'''
if __name__ == '__main__':
import string
fp = open('JCP099.py')
a = fp.read()
fp.close()
fp = open('JCP098.py')
b = fp.read()
fp.close()
fp = open('C.txt','w')
l = list(a + b)
l.sort()
s = ''
s = s.join(l)
fp.write(s)
fp.close()