Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
lesson4_1
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
1688e088
authored
Feb 03, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
01bc0008
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
135 additions
and
10 deletions
diy1.py
test1.py
diy1.py
deleted
100644 → 0
View file @
01bc0008
username
=
"python"
# 保存在服务器数据库中的用户账号(正确的账号)
userpassword
=
"123456"
# 保存在服务器数据库中的用户密码(正确的密码)
# 请用input()实现用户输入账号、密码的功能
name
=
input
(
"请输入账号"
)
word
=
input
(
"请输入密码"
)
# 如果用户输入的账号、密码正确,提示登陆成功
test1.py
0 → 100644
View file @
1688e088
# 输出 Hello World!
# print("Hello World!")
# 输入 食物名称
# input_food = input("今晚要吃什么:")
# 输出 要吃的食物
# print("今晚我要吃-", input_food)
#counter = 100 #整数类型变量
#miles = 100.0 #浮点型变量
#name = "bellcode" #字符串型变量
# 输出每个变量的类型
#print(type(counter))
#print(type(miles))
#print(type(name))
"""
# 连续赋值相同的值
a = b = c = 1
print(a)
print(b)
print(c)
# 连续赋值不同的值
x , y , z = 1 , 2 , 3
print(x, y, z)
"""
"""
这是一个多行注释
使用print函数
输出Hello World!
print("Hello World!")
x = 21
y = 8
# 加运算
print("x+y=", x+y)
# 减运算
print("x-y=", x-y)
# 乘运算
print("x*y=", x*y)
# 除运算
print("x/y=", x/y)
# 取整数运算
print("x//y=", x//y)
# 取余运算
print("x
%
y=", x
%
y)
# 幂次方运算
print("x**y=", x**y)
# 习题
# 输入三角形的底
h=int(input("请输入三角形的高:"))
# 输入三角形的高
w=int(input("请输入三角形底:"))
# 查看底和高的数据类型
print(type(h))
print(type(w))
# 打印三角形的面积
print("该三角形的面积为", h*w/2)
x = 2.9
x = int(x) #向下取整
print(x)
print(type(x)) #输出数据类型
#类型转换需要一步一步操作
x = "2.9" #字符串类型
x = float(x) # 不可以一次强制转换两下
print(x)
print(type(x))
x = 2
z = complex(x) #复数
print(z)
print(type(z))
y = 3
z = complex(y,x)
print(z)
# z = a+bi i**2 = -1
x = 21
# 查看x的类型
print("第一次查看:", type(x))
# 将整形转换成浮点型
x = float(x)
print("第二次查看:", type(x))
x = 21
y = 8
# 将x,y转换成复数z
z = complex(x,y)
print(z)
print(type(z))
# 创建字符串
str1 = 'hahaha'
str2 = "hahaha"
str3='''hahaha''' #避免和三个双引号冲突
print(str1, str2, str3)
# 创建一个字符串
string = "Hello World!"
# 01234567891011
#输出整个字符串
print("string=", string)
#输出字符串的第一个元素
print("string[0]=", string[0])
#输出字符串最后一个元素
print("string[-1]=", string[-1])
# 输出字符串的第一位到第七位的元素
print("string[1:8]=", string[1:8]) #[1,8)前闭后开的区间
#输出字符串的第一位到倒数第四位
print("string[1:-3]=", string[1:-3]) #[1,-3)前必后开的区间
# 步长为正数
print("string[::2]=", string[::2]) #::前面默认位置是0,步长为2
#步长为负数
print("string[::-1]=", string[::-1]) #::前面默认位置是-1,步长为-1
print("string[::-2]=", string[::-2]) #::前面默认位置是-1,步长为-2
print("string[1:10:2]=", string[1:10:2]) # [1,10) 前闭后开区间,步长为2
print("string[10:1:-2]=", string[10:1:-2]) # [10,1) 前闭后开区间,步长为-2
"""
#习题:截取"llo W" 写出至少八种方法
string
=
"Hello World!"
# 01234567891011 负数从末尾开始
print
(
string
[
2
:
7
])
print
(
string
[
-
10
:
-
5
])
print
(
string
[
2
:
-
5
])
print
(
string
[
-
10
:
7
])
print
(
string
[
2
:
5
]
+
string
[
5
:
7
])
print
(
string
[
-
10
:
5
]
+
string
[
5
:
7
])
print
(
string
[
2
:
7
:
1
])
print
(
string
[
-
10
:
-
5
:
1
])
print
(
string
[
2
:
-
5
:
1
])
print
(
string
[
-
10
:
7
:
1
])
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment