ptyhon基础篇 day1
1.变量
print('helloworld!')
name = 'alex'
name2 = 'jack'
print(name,name2)
2.input
#用户输入
username = input('username: ')
print(type(username))
age = int(input('age: '))
print(type(age))
job = input('job: ')
salary = input('salary: ')
3.字符串
#格式化字符串
info = '''
------------info----------
username:%s
age:%s
job:%s
salary:%s
'''%(username,age,job,salary) print(info)
4.用户登录
#密码隐藏
import getpass
username = input('username:')
pwd = getpass.getpass(('password:'))
print(type(pwd))
print(username,pwd)
#用户登录验证
username = 'alex'
password = '123' _username = input('username: ').strip()
_password = input('password: ') if username == _username and password == _password:
print('%s login ...'%username)
else:
print('error..')
5, while .猜年龄
#单次猜年龄,str() > int()
old_of_alex = '33'
guess_old = input('your guess old : ') old_of_alex1 = 33
guess_old1 = int(input('your guess old : ')) if guess_old == old_of_alex :
print('you are right') elif guess_old > old_of_alex:
print('it is too bigger') elif guess_old < old_of_alex:
print('it is too smaller')
#无限次 猜年龄
old_of_alex = 33
while True:
guess_old = input('your guess old : ').strip()
if guess_old.isnumeric():
guess_old = int(guess_old) if guess_old == old_of_alex :
print('you are right')
break elif guess_old > old_of_alex:
print('it is too bigger') elif guess_old < old_of_alex:
print('it is too smaller')
else:
print('error... please enter number')
#3次 猜年龄
old_of_alex = 33
count = 0
while True:
guess_old = input('your guess old : ').strip()
count +=1 if count <= 3:
if guess_old.isnumeric():
guess_old = int(guess_old) if guess_old == old_of_alex :
print('you are right')
break elif guess_old > old_of_alex:
print('it is too bigger') else:
print('it is too smaller')
else:
print('error... please enter number') else:
print('fuck off')
break
#3次 猜年龄 while count < 3:
old_of_alex = 33
count = 0
while count < 3:
guess_old = input('your guess old : ').strip()
count +=1
if guess_old.isnumeric():
guess_old = int(guess_old) if guess_old == old_of_alex :
print('you are right')
break elif guess_old > old_of_alex:
print('it is too bigger') else:
print('it is too smaller')
else:
print('error... please enter number')
print('fuck off')
#3次 猜年龄 while count < 3:
# else:print('fuck off')
old_of_alex = 33
count = 0
while count < 3:
guess_old = input('your guess old : ').strip()
count +=1
if guess_old.isnumeric():
guess_old = int(guess_old) if guess_old == old_of_alex :
print('you are right')
break elif guess_old > old_of_alex:
print('it is too bigger') else:
print('it is too smaller')
else:
print('error... please enter number')
else:
print('fuck off')
6.continue break
#while中contine , break 的区别
#测试1
count = 0
while True:
print('count : ',count)
count +=1
if count == 10000:
continue #while是死循环,跳出本次循环,会继续循环下一次,死循环 #测试2
count1 = 0
while True:
print('count1 : ',count1)
count1 +=1
if count1 > 19000:
break # 跳出循环,终止距离break最近的那个循环,while
#for 循环中continue和break效果相同
count = 0
for i in range(10):
if count == 5:
continue #跳出本次循环,count = 5 跳出for循环,终止循环下去
print(count)
count +=1 print('\n-----\n') count1 = 0
for i1 in range(10):
if count1 == 5:
break
print(count1)
count1 +=1
7.for循环
#for 循环
for i in range(10):
print('loop',i)
#for (start,stop,step)
for i in range(0,100,3):
print(i)
# for 循环实现 3次 猜年龄
old_of_alex = 33
for count in range(3): guess_old = int(input('your guess old : ').strip()) if guess_old == old_of_alex :
print('you are right')
break elif guess_old > old_of_alex:
print('it is too bigger') else:
print('it is too smaller') print('too times ... fuck off')
# 猜年龄 可以 一直询问
old_of_alex = 33
count = 0
while True:
guess_old = input('your guess old : ').strip()
count +=1
if guess_old.isnumeric():
guess_old = int(guess_old) if guess_old == old_of_alex :
print('you are right')
break elif guess_old > old_of_alex:
print('it is too bigger') else:
print('it is too smaller')
else:
print('error... please enter number') if count == 3:
choice = input('do you want to again [y/n]? > ').strip()
if choice == 'y':
count = 0
elif choice == 'n':
break
8.嵌套
#循环嵌套 for i in range(10):
print('-----',i)
for j in range(10):
print(i,j)
9.整型 长整型
#整形,长整型
'''
Python2.x中有int long Python3.x中没有长整型概念了! >>> type(2**10000)
<class 'int'> '''
10 .三目运算符
#三元运算符
'''
>>> a,b = 1,3
>>> max = a if a>b else b
>>> max
3
'''
作业:三次锁定
''' 编写用户登录接口
1.输入用户密码
2.认证成功显示欢迎信息
3.输错3次锁定 '''
username = 'alex'
password = '123'
count = 0 while count < 3:
_username = input('USERNAME : ').strip()
_password = input('PASSWORD : ').strip()
count += 1 if username == _username and password == _password:
print('''
-------------------
welcome the VIP %s
-------------------
'''%(username))
break else:
print('用户名或密码错误,请重新输入\n') else:
print('超过3次,锁定登录')
ptyhon基础篇 day1的更多相关文章
- python基础篇-day1
python基础篇 python是由C语言写的: pass 占位符: del,python中全局的功能,删除内存中的数据: 变量赋值的方法: user,pass = 'freddy','freddy1 ...
- C#多线程之基础篇3
在上一篇C#多线程之基础篇2中,我们主要讲述了确定线程的状态.线程优先级.前台线程和后台线程以及向线程传递参数的知识,在这一篇中我们将讲述如何使用C#的lock关键字锁定线程.使用Monitor锁定线 ...
- 一步步学习javascript基础篇(0):开篇索引
索引: 一步步学习javascript基础篇(1):基本概念 一步步学习javascript基础篇(2):作用域和作用域链 一步步学习javascript基础篇(3):Object.Function等 ...
- 2000条你应知的WPF小姿势 基础篇<15-21>
在正文开始之前需要介绍一个人:Sean Sexton. 来自明尼苏达双城的软件工程师,对C#和WPF有着极深的热情.最为出色的是他维护了两个博客:2,000Things You Should Know ...
- ABP框架实践基础篇之开发UI层
返回总目录<一步一步使用ABP框架搭建正式项目系列教程> 说明 其实最开始写的,就是这个ABP框架实践基础篇.在写这篇博客之前,又回头复习了一下ABP框架的理论,如果你还没学习,请查看AB ...
- C#多线程之基础篇2
在上一篇C#多线程之基础篇1中,我们主要讲述了如何创建线程.中止线程.线程等待以及终止线程的相关知识,在本篇中我们继续讲述有关线程的一些知识. 五.确定线程的状态 在这一节中,我们将讲述如何查看一个线 ...
- C#多线程之基础篇1
在多线程这一系列文章中,我们将讲述C#语言中多线程的相关知识,在多线程(基础篇)中我们将学习以下知识点: 创建线程 中止线程 线程等待 终止线程 确定线程的状态 线程优先级 前台线程和后台线程 向线程 ...
- iOS系列 基础篇 03 探究应用生命周期
iOS系列 基础篇 03 探究应用生命周期 目录: 1. 非运行状态 - 应用启动场景 2. 点击Home键 - 应用退出场景 3. 挂起重新运行场景 4. 内存清除 - 应用终止场景 5. 结尾 本 ...
- iOS系列 基础篇 04 探究视图生命周期
iOS系列 基础篇 04 探究视图生命周期 视图是应用的一个重要的组成部份,功能的实现与其息息相关,而视图控制器控制着视图,其重要性在整个应用中不言而喻. 以视图的四种状态为基础,我们来系统了解一下视 ...
随机推荐
- angular cli
1. 安装cnpm: npm install -g cnpm --registry=https://registry.npm.taobao.org 2. 安装angular/cli: cnpm ins ...
- 随手练——HDU 1284 动态规划入门
#include <iostream> #include <algorithm> #include <string.h> using namespace std; ...
- windows下使用Git
如何在windows下使用Git? 通过这里下载Git bash,你就可以像在Linux命令行一样操作git工具. 进入Git bash环境,默认是在当前用户路径下. 在Linux下,我们有根目录,在 ...
- C#网络Socket编程
1.什么是Socket Sockets 是一种进程通信机制,是一个通信链的句柄(其实就是两个程序通信用的) 2.分类 流式套接字(SOCK_STREAM):提供了一种可靠的.面向连接的双向数据传输服务 ...
- 404 Note Found队 Alpha7
目录 组员情况 组员1(组长):胡绪佩 组员2:胡青元 组员3:庄卉 组员4:家灿 组员5:凯琳 组员6:翟丹丹 组员7:何家伟 组员8:政演 组员9:黄鸿杰 组员10:刘一好 组员11:何宇恒 展示 ...
- LWIP network interface 即 LWIP 的 硬件 数据 接口 移植 详解 STM32 以太网数据 到达 的第二站: void ethernetif_input( void * pvParameters )
根据 上一篇 文章 , ETH DMA 数据中断 会 发送 一个信号量 ,我使用 全局 搜索 这个信号量 s_xSemaphore 得到 一下 几个 值 根据 这个 分析 我们找到了 数据 的 ...
- 修改jupyter notebook的默认路径
我的系统环境是win10,安装了anaconda3 for python 3.6.6首先需要配置notebook的变量环境:打开 cmd 输入命令 jupyter notebook --generat ...
- JS模拟Dictionary
function Map() { this.keys = new Array(); this.data = new Array(); //添加键值对 this.set = function (key, ...
- 使用 runtime 实现字符串转方法,并传递参数
利用runtime的动态机制实现字符串转方法并传递参数 使用 SEL 关键字引用方法声明,使用 methodForSelector 寻找方法实现, 使用函数指针调用方法. - (void)action ...
- Mac python3连接mysql
Mac python3连接mysql 安装方法1: 1.pip3 install --upgrade pip //升级pip版本 2.sudo python3 /Library/Frameworks/ ...