python学习笔记day1
程序员文章站
2024-01-15 15:26:46
...
python学习笔记day1
今天是2020年5月20日,终于开始写博客了,小白一个,记录每一天成长,不鸣则已一鸣惊人,未来可期。
python2和python3有一点变化,py3可以直接识别中文,但是偏移2必须添加utf-8
第一天主要是对Python有个大致了解,然后学习了基础的书写语法,了解了一下基本概念,一直是在OneNote上做笔记,现在转载博客,就有点乱,算是复习了,以后如果基本上每天的内容都是在这个上面来进行做笔记了,加油!
'''
a = print(1+2+3+4+5)
b = 5
print(a*b)
a = "中文"
b = "语文"
print(a+b)
print(100)
a = input("请输入数字:")
if a < "3":
aa = 1
print(aa)
elif a > "8":
aa = 2
print(aa)
else:
aa = 3
print(aa)
print ("------------------------------------")
'''
'''
a = 5
b = 0
```python
while a == 5:
print("千古李白")
print(1230)
print ("四月人间")
print(456)
b = b + 1
print(b)
if b == 5:
a = 1
print("结束")
'''
'''
count = 1
sun = 0
while count <=100:
sun = sun + count
count = count + 1
print (sun)
#计算1+2+3......+100
'''
#用户登录(三次机会重试)
user_name = 'admin'
password = '123456'
chance = 0
while chance < 3:
chance += 1
name = input("请输入用户名:")
pw = input("请输入密码:")
if name == user_name :
if pw == password :
print("登录成功!")
break
else:print("用户名或密码输入错误,请重新输入!")
else: print("用户名或密码输入错误,请重新输入!")
if chance == 3:
print("今天的登录次数用完了,请明天再来")
#1.使用while循环输出 1 2 3 4 5 6 8 9 10
count = 0
while count < 10:
count += 1
if count == 7:
continue
print(count)
#2.求1-100的所有数的和
count = 1
sum = 0
while count <= 100:
sum += count
count += 1
print(sum)
#3.输出1-100内的所有奇数
count = 0
odd = 0
while count < 50:
odd = count * 2 + 1
count += 1
print(odd)
#4.输出1-100内的所有偶数
count = 0
even = 0
while count < 50:
count += 1
even = 2 * count
print(even)
#5.求1-2+3-4+5-...-98+99的结果
#方案一:
count = 0
change = 0
sum = 0
while count < 99:
count += 1
if count % 2 == 0:
change = -1 * count
else:
change = count
sum += change
print(sum)
#方案二:
power = 1
count = 0
sum = 0
while count < 99:
count += 1
power += 1
sum = sum + count*((-1)**power)
print(sum)
学习前辈初学python时候的代码,学习前辈思路,以及排版。
上一篇: Word 标题编号变成竖线的解决方案
下一篇: 创建一颗最优二叉树(哈夫曼树)