语句与语法

----------以下部分内容摘自雨辰老师教学

 

x = 5
print(math.pow(x, 2))  # .pow(x,2):计算X的平方
if x > 3:  # 选择执行语句
    print('大于3')
else:
    print('小于3')
for i in range(1, 6):  # 迭代语句
    print(i ** 2)

while True:  # 编辑一个猜数字游戏,强制循环
    txt = input('请输入一个数字:')  # 强制缩进
    if txt == 'stop':
        break  # 进一步强制缩进
    elif not txt.isdigit():
        print('您没有输入数字!!')
    else:
        num = int(txt)
        if num < 20:
            print('您输入数字太小!')
        elif num > 20:
            print('您输入的数值太大了!')
        else:
            print('恭喜您猜对了!!!')

 

name = '吃鸡侠'  # 赋值语句
x = 5
name, age = '吃鸡侠', 30
(name, age) = ('吃鸡侠', 30)
[name, age] = ['吃鸡侠', 30]
a, b = 5, 10
print(a)
print(b)
a, b = b, a  # 变量交换值
print(a)
print(b)
a, *b = '大吉大利'
print(a)
print(b)
a, *b, c = '大吉大利'
print(a)
print(b)
print(c)
a = 5
b = 5
a, b = 5, 5
a = b = 5  # 多目标赋值
a = a + 10  # 参数化赋值
print(a)
b += 10
print(b)

name = input('请输入员工姓名:\n')
job = input('请输入员工工作:\n')
salary = float(input('请输入员工薪资:\n'))
print("员工姓名:{}".format(name))
print("员工职位:{}".format(job))
print("员工工资:{}".format(salary))

name = 'Tom'
job = 'Dev'
salary = 8000.333333
print("员工姓名:{}".format(name))
print("员工职位:{}".format(job))
print("员工工资:{}".format(salary))
print("=" * 30)
print(name, job, salary, sep=' | ')  # sep=,手动指定分隔符
print("=" * 30)
print(name, end=' , ')  # end=,手动指定结束符
print(job, end=' , ')
print(salary)
print("=" * 30)
print("薪资:{:12,.2f}".format(salary))  #:.2小数点保留2位,f是浮点型/','是分割符,12是字符长

 

posted @ 2018-02-21 12:28  炎之朱雀  阅读(192)  评论(0编辑  收藏  举报