第一周作业_Chapter 2 课后练习

2-1 简单消息

代码:

favorite_fruit = "apples"

print(favorite_fruit)

运行结果:

2-2 多条简单消息

代码:

favorite_fruit = "apples"
print(favorite_fruit)
favorite_fruit = "pears"
print(favorite_fruit)

运行结果:


2-3 个性化信息

代码:

usename = "Adam"
str = "Hey " + usename + ", would you like to watch movies with me?"
print(str)
运行结果:

2-4 调整名字的大小写

代码:

name = "Adam"
print(name.lower())
print(name.upper())
print(name.title())

运行结果:


2-5 名言

代码:

str = 'Fuller once said, "The darkest hour is that before the dawn."'

print(str)

运行结果:


2-6 名言2

代码:

famous_person = "Fuller"
message = famous_person + ' once said, "The darkest hour is that before the dawn."'
print(message)

运行结果:


2-7 剔除人名中的空白

代码:

name = "\tAdam\t"
print(name + ".\n---------------------\n")
print(name.lstrip() + ".")
print(name.rstrip() + ".")

print(name.strip() + ".")

运行结果:


2-8 数字8

代码:

print(2+6)
print(10-2)
print(2*4)
print(16/2)

运行结果:


2-9 最喜欢的数字

代码:

num = 6
message = "My favorite number is " + str(num) + "."
print(message)

运行结果:


2-10 添加注释

代码:

# coding=utf-8
num = 6
#str()将数字转化成字符串
message = "My favorite number is " + str(num) + "."
print(message)

运行结果:



2-11 python之禅

输入import this,显示:


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值