Learn Python The Hard Way (习题1)

虽然前期已通过自学,完成了python基础部份的学习,但是对于实践方面的实操较少。为了让自己在读下一本编程书籍前打下良好的基础,通过《笨办法学python》这本书复习并提高自已的编程能力,以跑例子为主,并进行相关知识点的归纳总结。(pycharm,版本是python3.8。)

Python3与Python2在使用print时区别在于是否需要添加()。

> 习题 1: 第一个程序

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.')

运行结果为:

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.

> 加分习题

> 1.让你的脚本再多打印一行。

print ("I'd much rather you 'not'.")
print("\n")
print ('I "said" do not touch this.')

运行结果:

I'd much rather you 'not'.


I "said" do not touch this.

> 2.让你的脚本只打印一行。

方法一:

print ("Hello World!",end="")
print ("Hello Again" ,end="")
print ("I like typing this." ,end="")
print ("This is fun.",end="")
print ('Yay! Printing.' ,end="")
print ("I'd much rather you 'not'.",end="")
print ('I "said" do not touch this.',end="")

运行结果:

Hello World!Hello AgainI like typing this.This is fun.Yay! Printing.I'd much rather you 'not'.I "said" do not touch this.

方法二:

print("How old are you?",
"How tall are you?",
"How much do you weigh? ")

运行结果:

How old are you? How tall are you? How much do you weigh? 

> 3.在一行的起始位置放一个 ‘#’ (octothorpe) 符号。它的作用是什么?自己研究一下。

#的作用就是注释,用于解释代码是怎样的逻辑或者作用,方便自己或者别的程序员阅读代码时能够理解代码的意义。# (井号)跟着的文字是不会被程序执行。只是做一个解释。

print ("Hello World!",end="")
#print默认是打印一行,结尾加换行。end=' '意思是末尾不换行,加空格
print ("Hello Again" )

运行结果:

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值