笨办法学python 习题1-2

1.加分习题1

1. 让你的脚本再多打印一行。
2. 让你的脚本只打印一行。
3. 在一行的起始位置放一个 ‘#’ (octothorpe) 符号。它的作用是什么?自己研究一下。

Notes:下面的习题均采用Python3进行测试,Python3的print需要添加括号进行输出,如

print ("Learn Python the hard way")

Python2的print不需要添加括号即可输出,如

print "Learn Python the hard way"

 

习题解析1

1.直接在原始文件,换行添加一个新的print即可。

#--coding:utf-8--
print ("Hello World!")
print ("Hello Again")
print ("I like typing this.")
print ("This is fun.")
print ('Yay! Printing.')
print ("I'd much rather you 'not'")
print ('I "said" do not touch this.')
print ('I Love Python')

2.将上述所有print连接成为一句,则

#--coding:utf-8--
print ("Hello World!",
     "Hello Again",
     "I like typing this.",
     "This is fun.",
     'Yay! Printing.',
     "I'd much rather you 'not'",
     'I "said" do not touch this.',
     'I Love Python')

3.#的作用就是注释,即anything after the # is ingored by python

 

2.加分习题2

  1. 弄清楚”#”符号的作用。而且记住它的名字。(中文为井号,英文为 octothorpe 或者 pound character)。
  2. 打开你的 ex2.py 文件,从后往前逐行检查。从最后一行开始,倒着逐个单词单词 检查回去。

  3. 有没有发现什么错误呢?有的话就改正过来.

  4. 朗读你写的习题,把每个字符都读出来。有没有发现更多的错误呢?有的话也一样

    改正过来。

 

习题解析2

# A comment,this is so you can read your program later.
# Anything after the # is ignored by python.

print ("I could have code like this.") # and the comment after is ignored

# You can also use a comment to "disable" or comment out a piece of code:
# print ("This won't run.")

print ("This will run.")

 

 

你可能感兴趣的:(Learn,Python,the,hard,way)