变量

变量是为了存储和程序运算过程中的一些中间结果 方便以后调用


(变量命名规则)

1. 要具有描述性
2.变量名只能_和数字,字母组成
3.不以中文 为命名
4.不能以数字开头
5.保留字符不能被使用

常量 常量名全部大写代表是常量

实验作业
#print("hello,world")

#x=41
#y=3

#name = "wangliang"
#print(x*y) #
#print(name)


实验作业
name = "a"

name2 = name

print(name,name2)

name = "jack"
print(name,name2)

内存回收 释放内存

del agr 被内存释放的变量

注释:
单行注释用 # 被注释内容
多行注释用3个 """被注释内容"""


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
death_age = 100

name = input ("your name:")
age = input ("you age:")
print( type(age))

#input 接收的所有数据都是数据都是字符串,即便你输入的是数字但依然会当成字符创来处理

#int integer = 把串 转成int , 用int(被转的数据)
#str strring =字符串 吧数据转成字符串 用str(被转的数据)
death_age = 100

name = input ("your name:")
age = input ("you age:")
print( type(age) )

#input 接收的所有数据都是数据都是字符串,即便你输入的是数字但依然会当成字符创来处理

#int integer = 把串 转成int , 用int(被转的数据)
#str strring =字符串 吧数据转成字符串 用str(被转的数据)
print ("Your name:",name)
##print("You can still live for" ,death_age - int(age),"years...")
print("You can still live for" + str(death_age - int(age)) + "years...")
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
age_of_princal = 46

guess_age =int( input(">>:") ) #赋值并转化 input 里面数据类型为 int类型


if guess_age == age_of_princal:

print("OK")

else: #python 强制要求缩进 按TAB 键

print("no")

# 输入年龄判断程序

age_of_princal = 46

guess_age =int( input(">>:") ) #赋值并转化 input 里面数据类型为 int类型


if guess_age == age_of_princal: #判断年龄等于实际就输出输出OK

print("OK")


elif guess_age > age_of_princal: #判断输入年龄大于实际年龄就输出 BIG
print("BIG")

else:
print("小于年龄") #否则就是小于年龄

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


#实验成绩打分程序
score = int(input("score:"))


if score >= 90:
print("A")
elif score >= 80:
print("B")
elif score >= 70:
print("C")

else:
print("不及格")

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 

内容来源于网络如有侵权请私信删除
你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!