可能有点啰嗦了,想说的都写在代码注释里面了。
顺便贴两张几天比较开心的图吧。
from sys import argv #没有这一行
script, filename = argv
txt = open(filename) #filenme 单词少了个a字母
print(f"Here's your file {filename}:") #引号前面少了个f
print(txt.read()) #少了个字母t
print("Type the filename again:")
file_again = input("> ")
txt_again = open(file_again)
print(txt_again.read()) #下划线应该改成点.
print("Let's practice everything.") #符号错了,都是用的单引号,但是Let’s这里也有一个
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 \nthe needs of love
nor comprehend passion from intuition
and requires an explanation
where there is none.
""" #24行的\n处不应该和下一个字母有空格。 27行 不应该有\这些内容了
print("--------------")
print(poem)
print("--------------") #少了两个引号分别在30的末尾和32的开头
print("How old are you?", end=' ')
age = input( "write your age:") #在括号里面添加了一些交互内容 同39
print("How tall are you?", end=' ')
height = input("write your height:") # 没有写这串代码
print("How much do you weigh?", end=' ')#少了个反括号
weight = input("write you weight:")
print(f"So, you're {age} old, {height} tall and {weight} heavy.")
print("\n--------------") #最后一次为了美观添加的
five = 10 - 2 + 3 - 6 #少了个6
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, 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 = 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))
print("--------------\n") #最后一次为了美观添加的
people = 20
cats = 30 #cates 多了个e
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.")
#我还调整了 input那一大段内容和 argv那段内容的顺序,因为我觉得argv这个需要使用者输入的地方,应该放在一开始比较好。
#好了改完了,大概花了30来分钟吧,现在是2021 09 10 00:49刚好是教师节。 学了12天python了,只学了这本书的一半,感觉有点太慢了。
#昨天还卡了一天,就是因为之前创建文件图便利没有在文件名前面加个ex,今天老哥回复我的时候我没及时看到,后来离开图书馆了菜看到
#说来也巧,我刚好在那之前看到了一段关于py文件开头不能带数字的话,之后看完老哥的回复,我又重新去翻那一本书,然后拍下来,可惜CSDN系统老是提示繁忙不让我回复他。
#今天教师节,除了以前教过我的老师之外,我还要特别感谢一下他,因为他不仅指出了我的错误,还教了我另外一种解决25题的方法。