python 基础实例
1. 下载安装包
https://www.python.org/ftp/python/2.7.14/python-2.7.14.amd64.msi # 2.7安装包 https://www.python.org/ftp/python/3.6.4/python-3.6.4-amd64.exe # 3.6安装包
2. 求1-2+3-4+5 ... 99 的所有数的和
1 n = 1 2 s = 0 3 4 while n < 100: 5 temp = n % 2 6 if temp == 0: 7 s = s -n 8 else: 9 s = s + n 10 n = n + 1 11 12 print(s)
3.使用while循环输出 1 2 3 4 5 6 8 9 10
1 n = 1 2 while n < 11: 3 if n == 7: 4 pass 5 else: 6 print(n) 7 n = n + 1 8 9 print('----end----')
4.求1-100的所有数的和
1 s = 0 2 while n < 101: 3 s = s + n 4 n = n + 1 5 6 print(s)
5.输出 1-100 内的所有奇数
1 n = 1 2 while n < 101: 3 temp = n % 2 4 if temp == 0: 5 pass 6 else: 7 print(n) 8 n = n + 1 9 10 print('----end----')
6.输出 1-100 内的所有偶数
n = 1 while n < 101: temp = n % 2 if temp == 0: print(n) else: pass n = n + 1 print('----end----')
7.登陆
#!/usr/bin/python3 # -*- coding: utf-8 -*- count = 0 while count < 3: username = input("please input you username: ") password = input("please input you password: ") count = count + 1 if username == "cdx" and password == "cdx123": print("login successed....") break else: print("login failed.....,you have %d " % (3 - count) ,"opportunity" )

浙公网安备 33010602011771号