1Python基础&demo
Posted jiangbigshrimp
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了1Python基础&demo相关的知识,希望对你有一定的参考价值。
模拟用户登录
name = input(‘请输入用户名‘)
password = input(‘请输入密码‘)
if name == ‘root‘:
if password == ‘root‘:
print(‘登录成功‘)
else:
print(‘密码错误‘)
else:
print(‘账号错误‘)
num = input(‘请输入一个a-c的字符‘)
if num == ‘a‘:
print(‘A‘)
elif num == ‘b‘:
print(‘B‘)
elif num ==‘c‘:
print(‘C‘)
else:
print(‘超出范围了‘)
简易版计算器
num1 = int(input(‘请输入第一个数字‘))
fu = input(‘请输入符号‘)
num2 = int(input(‘请输入第二个数字‘))
if fu == ‘+‘:
num3 = num1 + num2
elif fu == ‘-‘:
num3 = num1 - num2
elif fu == ‘*‘:
num3 = num1 * num2
elif fu == ‘/‘:
num3 = num1 / num2
else:
print(‘符号不解析‘)
print(num3)
计算一个数是奇数还是偶数
num = int(input(‘请输入一个数‘))
if num % 2 == 0:
print(‘偶数‘)
else:
print(‘奇数‘)
用while循环输入1-10,没有7
count = 0
while count < 10:
count = count + 1
if count == 7:
continue
else:
print(count)
用while求1-100的和
my_sum = 0
count = 1
while count <= 100:
my_sum = my_sum + count
count = count + 1
print(my_sum)
一百以内的偶数,换成0的话就是奇数
count = 1
while count <= 100:
if count % 2 == 1:
pass
count = count + 1
else:
print(count)
count = count + 1
num = 1
while num <=3:
name = input(‘输入名字‘)
if name == ‘root‘:
print(‘登录成功‘)
break
else:
print(‘不正确‘)
num = num + 1
以上是关于1Python基础&demo的主要内容,如果未能解决你的问题,请参考以下文章