笨办法学python习题1-10

本文是Python学习的习题解析,涵盖了注释、字符串操作、变量、打印格式化等内容。通过一系列的练习,介绍了如何使用#进行注释,理解字符串的连接与格式化输出,以及变量的命名和错误检查。还涉及到了数学计算和字符串包含的判断,强调了错误检查和学习习惯的重要性。
摘要由CSDN通过智能技术生成
#第一个程序
# -*- 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('T "said" do not touch this.')
print("I love you!")

加分练习

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

加一句print('\n')

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 "sai" do not touch this.',end="")

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

#就是注释的意思,所以该行不会被显示

习题2注释和井号

# -*- coding: utf-8 -*-

# 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. 弄清楚”#”符号的作用。而且记住它的名字。(中文为井号,英文为 octothorpe 或者 pound character)。

2. 打开你的 ex2.py 文件,从后往前逐行检查。从最后一行开始,倒着逐个单词单词检查回去。

3. 有没有发现什么错误呢?有的话就改正过来.

4. 朗读你写的习题,把每个字符都读出来。有没有发现更多的错误呢?有的话也一样改正过来。

 

习题3数学和数据计算

# -*- coding: utf-8 -*-
print("I will now count my chickens:")

print("Hens",25 + 30 / 6)

print("Roosters", 100 - 25 * 3 % 4)
print(4 % 2)
print("Now I will count the eggs:")
print(3 + 2 + 1 -5 + 4 % 2 -1 / 4 + 6)
print("Is it true that 3 + 2 < 5 -7 ?")
print(3 + 2 < 5 -7)
print(
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值