标签:含义 死循环 div 脚本 logs 内容 多行注释 odi rect
‘and‘、‘as‘、‘assert‘、‘break‘、‘class‘、‘continue‘、‘def‘、‘del‘、‘elif‘、‘else‘、‘except‘、‘exce‘、‘finally‘、‘for‘、‘from‘、‘if‘、‘is‘、‘in‘、‘global‘、‘import‘、‘lambda‘、‘not‘、‘or‘、‘pass‘、‘print‘、‘raise‘、‘retuen‘、‘try‘、‘while‘、‘with‘、‘yield‘
Name = "Yuhl1"
Age = 27
Name 是变量名,Yuhl1是变量值。下边Age同等
# 被注是的内容
""" 被注释的内容 """
在linux下创建一个.py文件,如下:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
_Author_ = "Yuhl"
Google_Mail = "cnblogs.honglin@gmail.com"
# 提示前台输入 关键字"input"
Google_Url = input("Please Input Google The Url:")
print(Google_Url)
print(Google_Mail)
user_name = input("Please input user name:")
password = input("Please input user password:")
if user_name == "Yuhl" and password == "abc123"
print("welcome %s Login successful"%user_name)
else:
print("username and password errors..")
--------------------------------------------------------------------------------------------------------------------------
my_age = 27
user_age = input("Please Input your age")
if user_age == my_age:
print("Congratulations, you got it")
elif user_age > my_age:
print("Oops,got guess bigger")
else:
print("Oops,got guess small")
打印十个数字
for line in range(10):
print(line)
流程控制 只打印数字5后面的
for line in range(10):
if line > 5:
print(line)
for循环猜年龄游戏【只能猜三次】
Yuhl_age = 27
for line in range(3):
user_age = input("Please Input user age:")
if user_age == Yuhl_age:
print("welcome your guessed it")
elif user_age > Yuhl_age:
print("input errors larger. please again input use age")
else:
print("input errors smaller. please again input use age")
for else结合使用猜年龄游戏讲解【for else】
Yuhl_age = 27
for line in range(3):
user_age = input("Please Input user age:")
if user_age == Yuhl_age:
print("welcome your guessed it")
elif user_age > Yuhl_age:
print("input errors larger. please again input use age")
else:
print("input errors smaller. please again input use age")
else:
exit("Too Many Attemots....")
PS:for else的含义是程序在正常执行的时候走else下的代码.如果中间程序有呗break的那么就不会执行else里代码
如果以下代码中的if 判断和break注视加上. 那么会执行else中的代码. 正常执行
如果以下代码中的if 判断和break注视未加. 那么不会执行else中的代码. 这就是区别. 中间截断不执行else下数据
for i in range(10):
print(i)
if i == 5:
break
else:
print("程序正常结束")
for 循环嵌套讲解01
for i in range(5):
for j in range(5):
print(i,j) # 此处pint包含3
if j > 3:
break # break跳出整个当前层循环. 只跳一层
print(i,j) # 此处pint不包含3. 逻辑问题
for 循环嵌套讲解02
for i in range(10):
for j in range(10):
print(i.j) # 此处print的话包含6
if j < 5:
break # break. 外层大循环依旧被执行过. 嵌套循环中j < 5就break了. 那么下边的print就不会被执行
continue # 跳出当前循环. 继续下一次循环
print(i,j) # 此处print的话不包含6 逻辑问题
while 死循环
count = 0
while True:
print("welcome your enter while Infinite loop.....%s"%count)
count += 1
while 语句if进行流控制.只打印某一点数据
count = 0
while True:
if count == 9999
print("welcome your enter while Infinite loop.....%s"%count)
break
count += 1
while 语句. 只打印多少次
count = 0
while count < 10:
print("welcome your enter while Infinite loop.....%s"%count)
count += 1
while 语句.加if控制流
count = 0
while True:
print("welcome your came to Heaven on earth")
if count == 5:
print("What a paradise on earth it is hell on earth")
break
count += 1
while 猜年龄游戏
count = 0
YHL_age = 27
while count < 3:
"""strip() #去除空格 isdigit()判断是不是整数 int()转换成整数 """
input_age = input("Please input age:").strip()
if input_age.isdigit():
input_age = int(input_age)
else:
continue
if input_age == YHL_age:
print("guess correct .....")
break
elif input_age == YHL_age:
print("guess the.")
else:
print("Guess a little")
count += 1
标签:含义 死循环 div 脚本 logs 内容 多行注释 odi rect
原文地址:https://www.cnblogs.com/SnailIng/p/9846568.html