笨办法学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.")

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值