《Python编程:从入门到实践》答案

本博客为Python编程初学者提供了一系列实用代码示例,涵盖了基本语法、字符串操作、列表使用、循环控制、条件判断及简单数据类型处理等内容,旨在帮助读者快速掌握Python编程基础。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

快乐又不要钱,为什么不呢?

【注】本文中所有的代码本人全部测试通过后才写在下面。考虑到夹杂结果图片太乱,所以没加。大家复制代码拿去运行即可。

前面章节的答案后续会补上。

【注】所有包含中文的代码都必须把编码设置成UTF-8才能正常运行。我用的是Geany,设置方法为:文档——设置文件编码——Unicode-——UTF-8

持续更新……

第二章

print("Hello my new life,\nhllo ,the technology world.\nplese be gentle to me.")

2-2

message="Hello my new life,\nhllo ,the technology world.\nplese be gentle to me."
print(message)

 2-3

name = 'Eric'
print('Hello '+name+', would you like to learn some pyghon today?')

2-4

name = 'eric'
print(name.title())
print(name.upper())
print(name.lower())

name = 'albert einstein'
saying="A person who never made a mistake never tried anything new."
print(name.title()+"once said"+": "+'\n\t"'+saying+'"')

name = ' albert einstein '
saying="A person who never made a mistake never tried anything new."
print(name.title())
print(name.title().lstrip().rstrip()+"once said"+": "+'\n\t"'+saying+'"')
print(name.strip())

print(80/10)
print(2*4)
print(10-2)
number=4
print("my favorite number is "+str(number))

 

  第三章 

names=['王辰','王杰','许博文','肖嘉良','田家铭','徐汉章']
for name in names:
	print(name)
names=['王辰','王杰','许博文','肖嘉良','田家铭','徐汉章']
for name in names:
	print('Hello '+name+" it's good to see you !")
names=['car','bicycle','shared bikes','motorcycle','bus']
for name in names:
	print('To be the truth ,my favorite vehicle is '+name+'.')

names=['泽东','和珅','胡雪岩','华罗庚','王羲之']
for name in names:
	print('Dear '+name+' ,i respectfully invite you to join me for dinner.')

 

names=['泽东','和珅','胡雪岩','华罗庚','王羲之']
for name in names:
	print('Dear '+name+' ,i respectfully invite you to join me for dinner.')

print('\n\nSorry the '+names[-2]+' has no time these days ,please call someone else.')
names[-2]='张三丰'
print(names)

for name in names:
	print('Dear '+name+' ,i respectfully invite you to join me for dinner.')

 

names=['泽东','和珅','胡雪岩','华罗庚','王羲之']
for name in names:
	print('Dear '+name+' ,i respectfully invite you to join me for dinner.')

print('\n\nSorry the '+names[-2]+' has no time these days ,please call someone else.')
names[-2]='张三丰'
print(names)

for name in names:
	print('Dear '+name+' ,i respectfully invite you to join me for dinner.'
评论 15
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

纸城

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值