1, C语言实验——图形输出(字符常量练习): http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1112
python中用print总是会出现回车空格,非常讨厌,然而,Python 3.0下print已经从语句变为函数了,我用的使python2.7.4,所以呢,还不行。。。。。但是我们可以用其他方法:
import sys sys.stdout.write("abc") sys.stdout.write("def")
#!/usr/bin/env python #coding:utf8 import sys for i in range(1, 6+1): for j in range(1, i+1): sys.stdout.write("#") sys.stdout.write('\n')
2, C语言实验——交换两个整数的值(顺序结构):http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1115
pathon交换两个值非常简单哦,看下面:
#!/usr/bin/env python #coding:utf8 x, y = raw_input().split() x , y = y, x print x,y
3, C语言实验——for循环打印图形(循环结构): http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1121
也许使因为刚使用,所以代码写的有点长,以后看看能不能精简些,欢迎拍砖
#!/usr/bin/env python #coding:utf8 import sys for i in range(1,7+1): if i<4: for j in range(1,5-i): sys.stdout.write(" ") for j in range(1,2*i): sys.stdout.write("*") sys.stdout.write("\n") elif i==4: for j in range(1,7+1): sys.stdout.write("*") sys.stdout.write("\n") else: for j in range(1,i-4+1): sys.stdout.write(" ") for j in range(1,6-2*(i-5)): sys.stdout.write("*") sys.stdout.write("\n")