(1)格式化输出(%% 第一个% 转译)

 # 格式化 输入 输出
name = input("Name:")
age = input("Age:")
job = input("Job:")
hobbies = input("Hobbies:") info = '''
---------index %s -------------
Name : %s
Age : %s
job : %s
Hobbies: %s
''' % (name, name, age, job, hobbies) print(info) # 如果输入的时候必须需要输入% 则输入%% 可以实现转义功能
msg = "我是%s,年龄%d,目前学习进度为80%%" % ('shine_rainbow', 18)
# result 我是shine_rainbow,年龄18,目前学习进度为80%
print(msg)

(2)基本数据类型1

 # int
a = 2 ** 3
print(type(a))
b = 2 ** 60
print(b)
# str
name = "my name is alex"
age = ""
msg = name+"\n"+age+"岁了\n"+"学习python 非常开心 开 心 开 心 心 "
print(msg)
# 对于input 从键盘上获取的内容,均为字符型
# name = input("请输入贵姓")
# print(name)
# print(type(name))
# 注意 在字符串拼接中str + str 为字符串拼接 str * int 为将这个内容复制多少次,在拼接在一起
print("hello world\n" * 10) # 打印10次hello world
# 字符串的拼接只能是双方都是字符串, 不可以跟数字和其他类型拼接
# print("hello"+2)
# 布尔类型 print(3 > 4) # 格式化输出
"""
需求:询问用户的姓名、年龄、工作、爱好,然后打印成如下格式:
----------------index of Alex Li----------------
Name : Alex Li
Age : 22
job : Teacher
Hobbies : girl
---------------end-------------------
"""
# name = input("please input name")
# age = int(input("please input age")) # 将str--->int
# job = input("please input job")
# hobbies = input("please input hobbies")
# msg =
# """
# ----------------index of %s----------------
# Name : %s
# Age : %s
# job : %s
# Hobbies : %s
# ---------------end-------------------
# """ % (name, name, age, job, hobbies)
# print(type(age))
# print(msg)

(3)基本逻辑语句

 # 逻辑运算 1.在没有()的情况下,not 优先级高于and and 高于or 即优先级()>not > and >or 同一优先级从左到右计算
print(3 > 4 or 4 < 3 and 1 == 1)
# f or f print (false)
print(1 < 2 and 3 < 4 or 1 > 2)
# t or f print(true)
print(2 > 1 and 3 < 4 or 4 > 5 and 2 < 1)
# t or f print(true)
# 求出下列逻辑语句的值
# x or y if x is false then y else x
print(8 or 4) print(0 and 3)
# if x is false then true else false
# x and y ,x true then y ,x false x
print(0 or 4 and 3 or 7 or 9 and 6)
# 0 or 3 or 7 or 6
# 3 or 7 or 6
# 3 or 6
#
# 判断子元素是否在原字符串(字典、列表、集合中)
print('喜欢' in 'jdljs;k;as喜欢')
print('a' in 'asdfds')
print('y' not in 'avd')
# true true true

(4)流程控制

 # if :
if 3 > 4:
print("")
else:
print("")
# if 多分支测试
score = int(input('请输入您的分数'))
if score > 100:
print("神童")
elif score >= 90:
print("A")
elif score >= 80:
print("B")
elif score >= 60:
print("C")
elif score > 10:
print("D")
else:
print("成绩低于10 太难受了。")

(5)循环控制

 # while循环
# 1-100的求和
# count = 0
# result = 0
# while count < 100:
# result += count
# count += 1
# print(result)
# 只要求出5-95之前的数字 注意使用continue
count = 0
result = 0
while count < 10:
count += 1
if count > 3 and count < 6:
continue
result += count print(result)

第一天测试题:

1. 使用while 循环输出 1 2 3 4 5 6 8 9 10

2.求1-100的所有数的和

3.输出1-100 内的所有奇数

4.1-2+3-4+5-...+99

5.三次登录

 # 使用while 循环输出 1 2 3 4 5 6 8 9 10
# count = 0
# while count < 10:
# count += 1
# if count == 7:
# continue
# print(count)
# print("----end----")
# 求1-100的所有数的和
# result = 0
# while count < 100:
# count += 1
# result += count
# print(result)
# 输出1-100 内的所有奇数
# result = 0
# while count < 100:
# count += 1
# if count % 2 == 0:
# continue
# result += count
# print(result)
# 或
# count = 1
# while count < 100:
# result += count
# count += 2
# print(result)
# 1-2+3-4+5-...+99
# count = 1
# sum1 = 0
# flag = 1
# while count < 100:
# if count % 2 == 0:
# flag = -1
# else:
# flag = 1
# sum1 = sum1 + count * flag
# count += 1
# print(sum1)
# 三次登录
username = "root"
password = ""
count = 3
while count > 0:
count -= 1
input_username = input("请输入用户名:")
input_password = input("请输入密码:")
if input_username.__eq__(username):
if input_password.__eq__(password):
print("登录成功,当前登录用户%s"%(username))
break
else:
print("登录失败,你还有%d次机会" %(count))
else:
print("登录失败,你还有%d次机会" %(count))

Python基础一(格式化输出、流程控制)的更多相关文章

  1. python基础_格式化输出(%用法和format用法)(转载)

    python基础_格式化输出(%用法和format用法) 目录 %用法 format用法 %用法 1.整数的输出 %o -- oct 八进制%d -- dec 十进制%x -- hex 十六进制 &g ...

  2. Python基础篇(格式化输出,运算符,编码):

    Python基础篇(格式化输出,运算符,编码): 格式化输出: 格式:print ( " 内容%s" %(变量)) 字符类型: %s  替换字符串      %d 替换整体数字  ...

  3. Python学习day05 - Python基础(3) 格式化输出和基本运算符

    figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...

  4. python基础(3)---流程控制

    流程控制 与C语言不通的是python的流程控制代码块不是用{}花括号表示的,而是强制缩进来控制的:而且缩进必须一致,官方推荐是使用4个空格,不建议使用tab(制表符)做缩进,一是不同的系统tab所占 ...

  5. 2.Python基础认识(格式化输出,while语句,运算符,编码,单位转化)

    Python基础认识 1.字符串的格式化初识及占位符的简单应用 字符串的格式化 按照既定的要求进行有规定排版的一种输出方式. #我们想要输出的格式如下: ----------------------- ...

  6. python基础(5):格式化输出、基本运算符、编码问题

    1. 格式化输出 现在有以下需求,让⽤户输入name, age, job,hobby 然后输出如下所⽰: ------------ info of Alex Li ----------- Name : ...

  7. Python基础(三)--流程控制之if、while、for,break与continue

    一.流程控制之if……else…… if语句是指编程语言中用来判定所给定的条件是否满足,根据判定的结果(真或假)决定执行给出的两种操作之一 if 条件1: 缩进的代码块 elif 条件2: 缩进的代码 ...

  8. python基础_格式化输出(%用法和format用法)

      目录 %用法 format用法 %用法 1.整数的输出 %o —— oct 八进制%d —— dec 十进制%x —— hex 十六进制 1 >>> print('%o' % 2 ...

  9. Python基础:十一、流程控制(if语句、while循环)

    一.流程控制——if循环 1.第一种语法: if条件: #引号是将条件与结果分开 结果1 #四个空格,或者一个tab键,这个是告诉程序满足条件的话,运行这个结果 结果2 #如果条件是真(True)执行 ...

  10. python基础02—运算符与流程控制

    运算符与流程控制 运算符 赋值运算 用'='表示,'='的左边只能是变量 算术运算 +.-.*:加.减.乘 /:除法运算,运算结果为浮点数 //:除法运算,运算结果为整数(商) %:求余 **:求幂 ...

随机推荐

  1. AcWing 244. 谜一样的牛 (树状数组+二分)打卡

    题目:https://www.acwing.com/problem/content/245/ 题意:有n只牛,现在他们按一种顺序排好,现在知道每只牛前面有几只牛比自己低,牛的身高是1-n,现在求每只牛 ...

  2. CTF | bugku | 字符?正则?

    做题链接 一个详细讲正则的网址1 一个详细讲正则的网址2 代码如下 <?php highlight_file('2.php'); $key='KEY{********************** ...

  3. VB.NET导出Excel 轻松实现Excel的服务器与客户端交换 服务器不安装Office

    说来VB.Net这个也是之前的一个项目中用到的.今天拿来总结下用途,项目需求,不让在服务器安装Office办公软件.这个也是煞费了一顿. 主要的思路就是 在导出的时候,利用DataTable做中间变量 ...

  4. ibatis 的使用

    1. 文本的使用 select  ‘day’+Num from Table;//Sql select convert(varchar,'day')+Num from Table;//ibatis

  5. 用 Flask 来写个轻博客 (33) — 使用 Flask-RESTful 来构建 RESTful API 之二

    Blog 项目源码:https://github.com/JmilkFan/JmilkFan-s-Blog 目录 目录 前文列表 扩展阅读 构建 RESTful Flask API 定义资源路由 格式 ...

  6. kubernetes原理

    kubernetes 核心组件 etcd:保存整个集群的状态 apiserver:提供资源操作的唯一入口,并提供认证.授权.访问控制.api注册和发现等机制 controller manager:负责 ...

  7. laravel 中url使用

    url() 通过url辅助函数(路由)生成:location.href = "{{url('user/index')}}"; 或者:location.href = "{{ ...

  8. linux下对rpm源码手工打补丁

    前言 通常情况rpm包组件管理方式下的linux环境,常用打补丁的方式只有一种:修改spec文件定义的Patch和patch字段,其实spec文件中调用的底层命令还是patch.  因为业务需要要编译 ...

  9. leetcode.排序.347前k个高频元素-Java

    1. 具体题目 给定一个非空的整数数组,返回其中出现频率前 k 高的元素. 示例 1: 输入: nums = [1,1,1,2,2,3], k = 2 输出: [1,2] 示例 2: 输入: nums ...

  10. Linux中通过grep命令检索文件内容和指定内容前后几行

    原文链接: https://www.linuxidc.com/Linux/2017-11/148390.htm Linux系统中搜索.查找文件中的内容,一般最常用的是grep命令,另外还有egrep命 ...