作为一个新手村村民,今天开始踏出coding的第一步,记录一下今天碰到的几个问题。
首先本人环境和工具:win10 python3.5 notepad++。
网络上教程:
print “xxx”
实际会出现如下报错:
File "E:\mypython\test", line 1
print "xxx"
SyntaxError: invalid syntax
修正为:print ('xxx')即可,或改‘’为“”
PS:同一语句中,不能重复用“”或‘’
即:
print ("i"said" do not touch this")
总结:除数字运算外,print的内容都需要加()并带 “”或‘’。
另外附上几个简单的小作业
1:(练习print的格式和敲字)
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.')
改为一行显示:(print多个字串)
print ("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')
2:(了解#注释)
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.")
3:(运用#注释,理解整个小程序的意思)
print ("i will now count my chickens:")
# 计算母鸡和公鸡的数量
print ("hens", 25 + 30 / 6)
print ("roosters", 100 - 25 * 3 % 4)
# 计算鸡蛋的数量
print ("now i will count my eggs:")
# 计算下列式子
print ( 3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6)
# 判断:3+2是否小于5-7
print ("is it true that 3 + 2 < 5 - 7?")
# 运算并判断
print (3 + 2 < 5 - 7)
print ("what is 3 + 2?", 3 + 2)
print ("what is 5 - 7?", 5 - 7)
# 输出结果
print ("oh!that is why it's false.")
# 更多练习
print ("how about some more?")
# 判断真伪
print ("is it greater?", 5 > -2)
print ("is it greater or equal?", 5 >= -2)
print ("is it less or euqal?", 5<= -2)
以上是今天的问题记录。
网友评论