这篇文章主要介绍了基于python的图表生成系统,具有一定借鉴价值,需要的朋友可以参考下。希望大家阅读完这篇文章后大有收获,下面让小编带着大家一起了解一下。
大家好,小编来为大家解答以下问题,《“笨办法”学python(第3版)》,笨办法学python第五版百度云,今天让我们一起来看看吧!
大家好,小编来为大家解答以下问题,笨办法学python 3电子书下载,笨办法学python3pdf完整版,现在让我们一起来看看吧!
Source code download: 本文相关源码
程序改错!!
源程序如下(wget
):
print("How old are you?", end=' ')
age = input()
print("How tall are you?", end=' ')
print("How much do you weigh?", end=' '
weight = input()
print(f"So, you're {age} old, {height} tall and {weight} heavy.")
, filename = argv
txt = open(filenme)
print("Here's your file {filename}:")
print(())
print("Type the filename again:")
file_again = input("> ")
txt_again = open(file_again)
print(txt_again_read())
print('Let's practice everything.')
print('You\'d need to know \'bout escapes
with \\ that do \n newlines and \t tabs.')
poem = """
\tThe lovely world
with logic so firmly planted
cannot discern \n the needs of love
nor comprehend passion from intuition
and requires an explanation
\n\t\twhere there is none.
"""
print("--------------)
print(poem)
print(--------------")
five = 10 - 2 + 3 -
print(f"This should be five: {five}"
def secret_formula(started)
jelly_beans = started * 500
jars = jelly_beans / 1000
crates = jars 100
return jelly_beans, jars, crates
start_point = 10000
beans, jars = secret_formula(start_point)
# remember that this is another way to format a string
print("With a starting point of: {}".format(start_point))
# it's just like with an f"" string
print(f"We'd have {beans} beans, {jars} jars, and {crates} crates.")
start_point = start_point / 10
print("We can also do that this way:")
formula = secret_formula(startpoint)
# this is an easy way to apply a list to a format string
print("We'd have {} beans, {} jars, and {} crates.".format(*formula))
people = 20
cates = 30
dogs = 15
if people < cats:
print "Too many cats! The world is doomed!"
if people < cats:
print("Not many cats! The world is saved!")
if people < dogs:
print("The world is drooled on!")
if people > dogs
print("The world is dry!")
dogs += 5
if people >= dogs:
print("People are greater than or equal to dogs.")
if people <= dogs
print("People are less than or equal to dogs.)
if people = dogs:
print("People are dogs.")
总共算上空行有100行的程序,我们先靠肉眼仔细分析一下:
第1段
print("How old are you?", end=' ')
age = input()
print("How tall are you?", end=' ')
print("How much do you weigh?", end=' '
weight = input()
print(f"So, you're {age} old, {height} tall and {weight} heavy.")
我们添加一个变量height
来接受用户输入的身高信息快码论文。而且第三个print语句少个右括号…python做简单笑脸pythonturtle画雪人。修改后这样:
第2段
, filename = argv
突然来这一句也太不正常了吧,咱新增argv模块的导入语句,都放在代码开头:
第3段
txt = open(filenme)
print("Here's your file {filename}:")
print(())
这代码毛病是真的多啊,首先第一句把filename
拼写错,第二句字符串格式化少个f,第三句把txt变量拼写错:
第4段
print("Type the filename again:")
file_again = input("> ")
txt_again = open(file_again)
print(txt_again_read())
只有一句有毛病,最后一句对文件txt_again对象调用read方法时的“."写成了下划线:
第5段
print('Let's practice everything.')
print('You\'d need to know \'bout escapes
with \\ that do \n newlines and \t tabs.')
这里就发现了一个问题,就是在Let's
那里的单引号应该前面放转义字符,第二句可能是理解有问题,没理解啥意思,应该能打印出来东西,不过意思就等打印出来再看了。
第6段
poem = """
\tThe lovely world
with logic so firmly planted
cannot discern \n the needs of love
nor comprehend passion from intuition
and requires an explanation
\n\t\twhere there is none.
"""
print("--------------)
print(poem)
print(--------------")
老毛病了,print语句的双引号,总少一个:
第7段
five = 10 - 2 + 3 -
print(f"This should be five: {five}"
第一句表达式不完成,根据程序的意思应该到得到数字5:
第8段
def secret_formula(started)
jelly_beans = started * 500
jars = jelly_beans / 1000
crates = jars 100
return jelly_beans, jars, crates
start_point = 10000
beans, jars = secret_formula(start_point)
终于碰到函数了,肯定毛病很多。。。首先定义函数的语句少个冒号!!(这个真难发现),然后其中的运算中有一句没有运算符号,调用函数的时候少一个变量接受返回值:
第9段
# remember that this is another way to format a string
print("With a starting point of: {}".format(start_point))
# it's just like with an f"" string
print(f"We'd have {beans} beans, {jars} jars, and {crates} crates.")
start_point = start_point / 10
print("We can also do that this way:")
formula = secret_formula(startpoint)
# this is an easy way to apply a list to a format string
print("We'd have {} beans, {} jars, and {} crates.".format(*formula))
介绍两种字符串格式化的用法,只有倒数第三句变量start_point拼写错了。
第10段
people = 20
cates = 30
dogs = 15
if people < cats:
print "Too many cats! The world is doomed!"
if people < cats:
print("Not many cats! The world is saved!")
if people < dogs:
print("The world is drooled on!")
if people > dogs
print("The world is dry!")
dogs += 5
if people >= dogs:
print("People are greater than or equal to dogs.")
if people <= dogs
print("People are less than or equal to dogs.)
if people = dogs:
print("People are dogs.")
这是一系列的条件判断语句?!挺简单的,但是按理说没学过啊,哈哈。毛病不少:第二行cats变量名写错;第四个if语句少个冒号;第一个print语句少了小括号;倒数第二个if语句又少了冒号,print语句也少了右边的引号。
以上我们分成十个部分用肉眼分析了这个程序,现在总体来看一下修改后的样子:
# 提示用户输入年龄,并存储在变量age中
print("How old are you?", end=' ')
age = input()
# 提示用户输入身高, 并存储在变量tall中
print("How tall are you?", end=' ')
height = input()
# 提示用户输入体重,并存储在变量weight中
print("How much do you weigh?", end=' ')
weight = input()
# 使用字符串格式化打印前面三个用户信息变量
print(f"So, you're {age} old, {height} tall and {weight} heavy.")
# 把文件对象保存在变量txt中
txt = open(filename)
# 字符串格式化打印文件名字
print(f"Here's your file {filename}:")
# 使用read方法读取文件内容并打印返回的字符串
print(())
# 打印语句提示用户再次输入文件名
print("Type the filename again:")
# 使用input接受用户输入的文件名,保存在file_again变量中
file_again = input("> ")
# 把新输入的文件对象保存在变量txt_again中
txt_again = open(file_again)
# 使用read方法读取文件内容并打印返回的字符串
print(())
# 打印语句
print('Let\'s practice everything.')
# 介绍转义字符的用法,打印转义字符本身和转行、制表符、单引号
print('You\'d need to know \'bout escapes
with \\ that do \n newlines and \t tabs.')
# 把固定格式的字符串存入变量poem中
poem = """
\tThe lovely world
with logic so firmly planted
cannot discern \n the needs of love
nor comprehend passion from intuition
and requires an explanation
\n\t\twhere there is none.
"""
# 打印poem变量里的字符,前后行用----间隔
print("--------------")
print(poem)
print("--------------")
# 把表达式的结果存在变量five中
five = 10 - 2 + 3 - 6
print(f"This should be five: {five}"
# 定义函数secret_formula,需要一个形参并且返回三个值
def secret_formula(started):
jelly_beans = started * 500
jars = jelly_beans / 1000
crates = jars - 100
return jelly_beans, jars, crates
# 给变量start_point赋值为10000
start_point = 10000
# 调用函数secret_formula,并用三个变量接受函数的三个返回值
beans, jars, crates = secret_formula(start_point)
# 两种字符串格式化格式
# remember that this is another way to format a string
print("With a starting point of: {}".format(start_point))
# it's just like with an f"" string
print(f"We'd have {beans} beans, {jars} jars, and {crates} crates.")
# 把变量start_point除以十,然后传递给函数,将返回值元组存储在变量formula中并打印
start_point = start_point / 10
print("We can also do that this way:")
formula = secret_formula(start_point)
# this is an easy way to apply a list to a format string
print("We'd have {} beans, {} jars, and {} crates.".format(*formula))
# 给三个变量赋值
people = 20
cats = 30
dogs = 15
if people < cats:
print("Too many cats! The world is doomed!")
if people < cats:
print("Not many cats! The world is saved!")
if people < dogs:
print("The world is drooled on!")
if people > dogs:
print("The world is dry!")
dogs += 5
if people >= dogs:
print("People are greater than or equal to dogs.")
if people <= dogs:
print("People are less than or equal to dogs.")
if people == dogs:
print("People are dogs.")
运行
第一次:
我们运行一下,因为根据程序要求,需要创建一个文档作为参数:
不出意外的直接产生了错误,就是转义字符那里,直接换行了确实有问题,咱放个转义字符在最后:
第二次
差点原地爆炸,def无效,把定义函数的语句放在代码开头后面的变量定义也是无效,看了好久才发现是前面那个print语句没有右括号!!
第三次
如果我没猜错的话,程序已经能很好的运行了,已经没有什么致命的问题来阻止它。现在我们来进行一番改良: 。。。 其实也没啥好改良的,程序没什么逻辑,都是一些散碎的知识点拼接在一起的,况且没有循环和条件语句参与少了很多乐趣,就这样把,写好注释,整理好格式已经确定拿下这个考试题了:
# 从sys导入argv模块,使脚本调用时接受两个参数
from sys import argv
# 两个参数是脚本名和一个文件名字
, filename = argv
# 提示用户输入年龄,并存储在变量age中
print("How old are you?", end=' ')
age = input()
# 提示用户输入身高, 并存储在变量tall中
print("How tall are you?", end=' ')
height = input()
# 提示用户输入体重,并存储在变量weight中
print("How much do you weigh?", end=' ')
weight = input()
# 使用字符串格式化打印前面三个用户信息变量
print(f"So, you're {age} old, {height} tall and {weight} heavy.")
# 把文件对象保存在变量txt中
txt = open(filename)
# 字符串格式化打印文件名字
print(f"Here's your file {filename}:")
# 使用read方法读取文件内容并打印返回的字符串
print(())
# 打印语句提示用户再次输入文件名
print("Type the filename again:")
# 使用input接受用户输入的文件名,保存在file_again变量中
file_again = input("> ")
# 把新输入的文件对象保存在变量txt_again中
txt_again = open(file_again)
# 使用read方法读取文件内容并打印返回的字符串
print(())
# 打印语句
print('Let\'s practice everything.')
# 介绍转义字符的用法,打印转义字符本身和转行、制表符、单引号
print('You\'d need to know \'bout escapes\
with \\ that do \n newlines and \t tabs.')
# 把固定格式的字符串存入变量poem中
poem = """
\tThe lovely world
with logic so firmly planted
cannot discern \n the needs of love
nor comprehend passion from intuition
and requires an explanation
\n\t\twhere there is none.
"""
# 打印poem变量里的字符,前后行用----间隔
print("--------------")
print(poem)
print("--------------")
# 把表达式的结果存在变量five中
five = 10 - 2 + 3 - 6
print(f"This should be five: {five}")
# 定义函数secret_formula,需要一个形参并且返回三个值
def secret_formula(started):
jelly_beans = started * 500
jars = jelly_beans / 1000
crates = jars - 100
return jelly_beans, jars, crates
# 给变量start_point赋值为10000
start_point = 10000
# 调用函数secret_formula,并用三个变量接受函数的三个返回值
beans, jars, crates = secret_formula(start_point)
# 两种字符串格式化格式
# remember that this is another way to format a string
print("With a starting point of: {}".format(start_point))
# it's just like with an f"" string
print(f"We'd have {beans} beans, {jars} jars, and {crates} crates.")
# 把变量start_point除以十,然后传递给函数,将返回值元组存储在变量formula中并打印
start_point = start_point / 10
print("We can also do that this way:")
formula = secret_formula(start_point)
# this is an easy way to apply a list to a format string
print("We'd have {} beans, {} jars, and {} crates.".format(*formula))
# 给三个变量赋值
people = 20
cats = 30
dogs = 15
if people < cats:
print("Too many cats! The world is doomed!")
if people < cats:
print("Not many cats! The world is saved!")
if people < dogs:
print("The world is drooled on!")
if people > dogs:
print("The world is dry!")
dogs += 5
if people >= dogs:
print("People are greater than or equal to dogs.")
if people <= dogs:
print("People are less than or equal to dogs.")
if people == dogs:
print("People are dogs.")
学习感悟:真是骚操作,从来没见过这种学习思路,大家都是把所有的语法一股脑看完才开始函数模块啥的,到目前还没接触循环条件语法都能写这么多的语句真是服了,很期待后期的学习效果,目前来说学习效果是达到非常的好,加油!!