day02

'''
用户与程序交互:
    input()  输入
    priut()  输出
username = input('输入提示信息:')
'''
username = input('请输入用户名')
print(username)
password = input('请输入密码')
print(password)

#如果
#usename == 'tant' True
#and:左右两边的条件都为True,否则为False
#password == '123'  True,执行if下的代码
if username == 'tank' and password == '123':
    # False and True    --->>  False
    print('登陆成功')
else:
    print('登陆失败')






# 占位符: %s
str1 = '很帅'
print('tank%s' % (str1,))   # tank很帅

str2 = '信念与我同在,我将无坚不摧!'

print('自信养成记1: %s' % (str2,))

pricel = input('请输入该用户当月扣费月租:')
all = input('请输入该用户当前余额: ')

print('亲爱的的移动用户,您当月月租为[%s]元,账户余额为[%s]元! '
      %(pricel,all))





#可变与不可变
#当数据修改时,1d不变称之为可变类型,否则称之为不可变类型。(默写)
#可变
List1 =['tank','jason']
print('List1修改前ID:',id(List1))
List1.append('徐峰')   #  ['tsnk','jason'].append(徐峰)
print(List1)
print('List1修改后ID:',id(List1))



#不可变:元组
tuple1=(1,2,3)
print(id(tuple1))
print(type(tuple1))
tuple1=(2,3,4)
print(id(tuple1))


# -算术运算符
print(1+1)  #2
n1 = 1
#  n1 = n1 + 1  # n1 +=1
#  print(n1)   #  2
n1  +=  1

# 赋值运算符: -=
print(10 - 1) # 9

# *=
print(12*12)  # 144
print(11/3)   # 3.666...
print(11//3)  # 3
print(11%3)   # 2

# 比较运算符
print(1 == 2)  # False
print(1 > 2)  # False
print(1 < 2)  # True
print(1 >= 2)  # False
print(1 <= 2)  # True

# is: 比较两个变量的id是否相等
X =10
print(id(X) == id(X))  # True
print(X is X)  # True


# 逻辑运算符
# and: 左右两边的条件都为True才为True,否则为False
print(X == 1 and X == 10)  # False
print(X == 10 and X == 10)  # True

# or: 判断两边的条件是否成立,其1成立则为True
print(X == 10 or X == 1)  # True

# not:取反
print(X == 10)  # True
print(not X == 10)  # False

# no-->and-->or
#           True or False
print(not X == 1 or X == 10 and X == 20)  # True

# 链式赋值
n = 10
y = n
z = y
print(n,y,z)

n = y = Z = 10
print(n,y,z)


# 交叉赋值
x = 10
y = 20
# x与y的值互换
# x = 20   y = 10
z = x  # 10
x = y  # 20
y = z  # 10

X = 10
Y = 20
#  10, 20 = y=10, x=20
x, y = y, x
print(x, y)  # 20 10


# 解压缩赋值
#         0  1  2
list1 = [1, 2, 3]
x = list1[0]
y = list1[1]
z = list1[2]
print(x, y, z)  # 1 2 3
x, y, z = list1
print(x, y, z)  # 1 2 3


'''
if分支
'''

#猜字符游戏:猜测用户输入的字符是否是9527.

number = 9527

guess = input('请输入猜测数字:')

print(guess)
print(type(guess))  # str

#把字符串类型转为整形
guess = int(guess)
print(type(guess))  #int

if guess == number:
    print('猜对了!')

elif guess < number:
    print('猜小了')

else:
    print('猜大了')

 

上一篇:Python 猜数小程序(练习)


下一篇:Python实现破解猜数游戏算法示例