- 博客(19)
- 收藏
- 关注
原创 笨办法22到目前为止你学到了什么?
结果之前学的内容,写了一小段from sys import argvscript, filename1, filename2 = argvdef add(a, b, c): return a + b + cdef rewind(f): f.seek(0)file1 = open(filename1, 'w')plus = add("\t 12345 \n", "I'll play
2017-09-21 17:58:11
377
原创 笨办法21函数的返回值
代码如下:把第3行的加号换成了减号def add(a, b): print "ADDING %d + %d" % (a, b) return a - bdef substract(a, b): print "SUBTRACTING %d - %d" % (a, b) return a - bdef multiply(a, b): print "MULTIP
2017-09-12 18:04:51
362
原创 笨办法20函数和文件
代码如下,在打印了第一行之后,多加入了一次函数seek()的操作:#coding:utf-8from sys import argvscript, input_file = argvdef print_all(f): # 打印从文件中读取的内容 print f.read() def rewind(f): # 将文件内部的指针重新指向开头 f.seek(0) def print_a_l
2017-09-12 14:54:20
375
1
原创 笨办法19函数和变量
以下为代码def cheese_and_crackers(cheese_count, boxes_of_crackers): #定义函数 print "You have %d cheeses!" % cheese_count print "You have %d boxes of crackers!" % boxes_of_crackers print "Man that's
2017-09-10 20:31:35
262
原创 笨办法18命名、变量、代码、函数
源代码如下:#coding: utf-8# this one is like your scripts with argvdef print_two(*args): arg1, arg2 = args print "arg1: %r, arg2: %r" % (arg1, arg2)# ok, that *args is actually pointless, we can ju
2017-09-06 17:46:50
295
原创 笨办法17更多文件操作
源代码如下from sys import argvfrom os.path import existsscript, from_file, to_file = argvprint "Copying from %s to %s" % (from_file, to_file)# We could do these two on one line too, how?input = open(from_
2017-09-04 18:11:14
277
1
原创 笨办法16读写文件
代码如下:#coding:utf-8from sys import argvscript, filename = argvprint "We're going to erase %r." %filename #提示语句,告知用户将抹掉文件print "If you don't want that, hit CTRL-C (^C)." #提示语句,停止操作的按键print "If you do
2017-08-30 17:46:14
363
原创 笨办法15读取文件
代码如下:#coding:utf-8from sys import argv script, filename = argv txt = open(filename) #将打开的文件内容赋值给变量txtprint "Here's your file %r:" % filename print txt.read() #读取txt的内容print "Type the filename again:"
2017-08-28 17:33:12
364
原创 笨办法14提示和传递
加分习题: 2. 将 prompt 变量改成完全不同的内容再运行一遍:将‘>’换成“please enter:” 3. 给你的脚本再添加一个参数,让你的程序用到这个参数:加入参数,dear以下为代码:from sys import argvscript, user_name, nike_name = argvprompt = "please enter: "print "Hi %s%s, I'
2017-08-22 17:04:33
402
1
原创 笨办法13参数、解包、变量_草稿
加分习题3:将 raw_input 和 argv 一起使用,让你的脚本从用户手上得到更多的输入。from sys import argvscript, first, second, third = argv'''print "The script is called:", scriptprint "Your first variable is:", firstprint "Your seco
2017-07-04 17:54:06
594
1
原创 笨办法12提示别人
老样子,把源代码乱改了一通:age = input("How od are you? ")height = raw_input("How tall are you? "), ("what?"), raw_input("again ")weight = raw_input("How much do you weight? ")print "So,you're %r old, %r tall and
2017-06-30 17:44:34
200
原创 笨办法11提问-raw_input
好气啊,写完了没发表,跑去改之前的一篇,结果把这篇顶掉了啊!说好的重新加载就恢复呢!?呢?!好气好气,,,源代码如下,有个改动print "How old are you?",age = raw_input()print "How tall are you?",height = raw_input()print "How much do you weigh?",weigh = raw_in
2017-06-29 17:52:13
598
原创 笨办法10那是什么?-转义
tabby_cat = "\t I'm tabbed in."persian_cat = "I'm split\non a line."backslash_cat = "I'm \\ a \\ cat."fat_cat = """I'll do a list:\t* Cat food\t* Fishies\t* Catnip\n\t* Grass"""print tabby_cat
2017-06-28 17:58:06
235
原创 笨办法09打印,打印,打印
# Here's some new strange stuff, remember type it exactly.days = "Mon Tue Wed Thu Fri Sat Sun"months = "Jan\nFeb\nMar\nMay\nJun\nJul\nAug"print "Here are the days: ", daysprint "Here are the months:"
2017-06-07 16:33:45
260
原创 笨办法08打印,打印
formatter = "%r %r %r %r"print formatter % (1, 2, 3, 4)print formatter % ("one", "two", "three", "four")print formatter % (True, False, False, True)print formatter % (formatter, formatter, formatter
2017-06-02 14:59:34
245
原创 笨办法07更多打印
print "Mary had a little lamb."print "Tts fleece was white as %s." % 'snow'print "And everywhere that Mary went."print "." * 10 # what'd that do?end1 = "C"end2 = "h"end3 = "e
2017-06-01 17:45:37
249
原创 笨办法05更多的变量和打印
my_name = 'Kuro Nico'my_age = 35 - 5 # Oh, no!heightcm = 7 * 10 + 4my_height = heightcm * 2.54 # inchesmy_weight = 10 % 4 * 90 # lbsmy_eyes = 'Blue'my_teeth = 'Whit
2017-06-01 17:22:22
276
原创 笨办法06字符串(string)和文本
代码如下:# coding : utf-8x = "There are %d types of people." % 10binary = "binary"do_not = "don't"y = "Those who know %s and those who %s." % (binary, do_not)print xprint y print "I said: %r." % xpri
2017-06-01 17:17:02
224
转载 欢迎使用优快云-markdown编辑器
欢迎使用Markdown编辑器写博客本Markdown编辑器使用StackEdit修改而来,用它写博客,将会带来全新的体验哦:Markdown和扩展Markdown简洁的语法代码块高亮图片链接和图片上传LaTex数学公式UML序列图和流程图离线写博客导入导出Markdown文件丰富的快捷键快捷键加粗 Ctrl + B 斜体 Ctrl + I 引用 Ctrl
2017-06-01 17:13:46
181
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人