(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. 基于Springmvc的登录权限拦截器

    1.什么是拦截器 拦截器是指通过统一拦截从浏览器发往服务端的请求来完成功能的增强. 使用场景:解决请求的共性问题(如:乱码问题,权限验证问题等) 2.拦截器的基本工作原理 springmvc可以通过配 ...

  2. 阿里云使用ssl免费证书

    购买免费证书 购买之后 申请证书 该域名必须添加一条TXT记录 根据提示添加记录 下载证书 我用的nginx做的映射,所以下载nginx nginx安装自行百度 将下载的文件解压到nginx目录下(创 ...

  3. delphi vlc 安装bug 处理编译错误"0" is an invalid value for the "DebugInformation" parameter of the "DCC"

    处理编译错误"0" is an invalid value for the "DebugInformation" parameter of the "DCC" [摘要:http://blog.csdn ...

  4. Oracle 11g Compound Trigger

    Original Link In Oracle 11g, the concept of compound trigger was introduced. A compound trigger is a ...

  5. StarUml3.10 Mac 注册key 破解

    /Applications/StarUML.app/Contents/Resources StarUML是用nodejs写的.确切的说是用Electron前端框架写的.新版本中所有的starUML源代 ...

  6. 《零基础学习Python制作ArcGIS自定义工具》课程简介

    Python for ArcGIS Python for ArcGIS是借助Python语言实现ArcGIS自动化行为的综合,它不止是如课程标题所述的“制作ArcGIS自定义工具”,还包括使用Pyth ...

  7. Asp.net core 使用log4net作为日志组件,记录日志到本地。

    原文:Asp.net core 使用log4net作为日志组件,记录日志到本地. GitHub demo :https://github.com/zhanglilong23/Asp.NetCore.D ...

  8. 【目录】redis 系列篇

    随笔分类 - redis 系列篇 redis 系列27 Cluster高可用 (2) 摘要: 一. ASK错误 集群上篇最后讲到,对于重新分片由redis-trib负责执行,关于该工具以后再介绍.在进 ...

  9. html中代替空格、大于号、小于号等字符编码

    数字表示法的不方便之处,在于必须知道每个字符的码点,很难记忆.为了能够快速输入,HTML 为一些特殊字符,规定了容易记忆的名字,允许通过名字来表示它们,这称为实体表示法(entity). 实体的写法是 ...

  10. Codeforces 1198E Rectangle Painting 2 最小点覆盖(网络流)

    题意:有一个n * n的棋盘,每个棋盘有某些矩形区域被染成了黑色(这些矩形区域有可能相交),问把所有黑色区域染成白色的最小花费是多少?你每次可以选择把一个矩形区域染成白色,花费是染色的矩形区域长和宽的 ...