《Python编程——从入门到实践》第二章习题解

# 2-1 简单消息
message = "Hello World !"
print( message )

# 2-2 多条简单消息
message = "Hello World !"
print( message )

message = "Hello Python !"
print( message )

# 2-3 个性化消息
user_name = input()
print( "Hello Eric, would you like to learn some Python today?" )

# 2-4 调整名字大小写
user_name = input()
print( user_name.lower() )
print( user_name.upper() )
print( user_name.title() )

# 2-5 名言
print( 'Albert Einstein once said,"A person who never tried anything new."' )

# 2-6 名言2
famous_person = "Albert Einstein"
message = famous_person + ' once said,"A person who never tried anything new."'
print( message )

# 2-7 剔除人名中的空白
message = "\n\tMike "
print( message )
print( message.lstrip())
print( message.rstrip())
print( message.strip())

# 2-8 数字8
print( 3 + 5 )
print( 9 - 1 )
print( 2 * 4 )
print( int( 16 / 2 ) )


# 2-9 最喜欢的数字
number = 6
message = "My favorite number is " + str(number)
print( message )

# 2-10 添加注释
'''
彭志奇 2018-3-7 显示我最喜欢的数字
'''
number = 6
message = "My favorite number is " + str(number)
print( message )
'''
彭志奇 2018-3-7 显示四则运算数字8
'''
print( 3 + 5 )
print( 9 - 1 )
print( 2 * 4 )
print( int( 16 / 2 ) )


# 2-11 Python之禅
import this



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值