版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_34929774/article/details/79175341
创建
1.New Project — Pure python — location(比如改为S14)
2.与S14右键 New — Directory (命名为day1)
3. 与day1右键New — Python File —(命名为var, for,guess……)
文本处理 第一种方法
name=input("name:")
age=input("age:")
job=input("job:")
SSS="""
----------info of %s-------------
姓名:%s
年龄:%s
工作:%s
"""%(name,name,age,job)
print(SSS)
if else+文本第二种
_usename='zheng'
_passnum="12345"
username=input("name:")
password=input('word:')
if _usename==username and _passnum==password:
print("welcom {N} to come".format(N=username))
else:1
print("invalue")
# *格式上的对齐,以及冒号*
for 循环
for i in range(10,20,2):
print("i=",i)
#输出10,12,14,16,18
#从10开始,每次间隔2,小于20.如果没有10默认从0开始,如果没有2默认间隔为1.
数据类型
i=10
print(type(i)) #---------------------int
i=“10”
print(type(i)) #---------------------str
i=int('10');
print(type(i)) #---------------------int
break 与 continue
break结束整个循环体i;continue结束本次的单次循环,进行下一次循环
count = 0
while True:
count = count + 1
print("count",count)
if count==10 :
break #---------------输出1 2 3 4 5 6 7 8 9 10
for i in range(0,10,2):
if i==4 or i==6 :
print("loop", i)
continue
print("hehe.....", i)
'''输出
hehe..... 0
hehe..... 2
loop 4
loop 6
hehe..... 8
'''
猜数字
my_age=23
count = 0
while count<3:
age=int( input("age:") )
count += 1
if my_age==age:
print("you get it")
break
elif age>my_age:
print("think bigger")
else:
print("think smaller")
if count==3:
again=input("do you want again ?")
if again =="n"or"N":
break
else:
count=0