Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

完成列表作业 #2

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions exercise/3变量/variable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

# # 练习一 变量的定义和使用
#
# 1. 定义两个变量分别为美元和汇率
# 2. 通过搜索引擎找到美元兑人民币汇率
# 3. 使用Python计算100美元兑换的人民币数量并用print( )进行输出

dollar = 100.00
exchange_rate = 6.42
rmb = dollar * exchange_rate



print("%f 美元兑换的人民币数量= %f " %(dollar,rmb))
78 changes: 78 additions & 0 deletions exercise/4序列/sequence.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# # 练习一 字符串
#
# 1. 定义一个字符串Hello Python 并使用print( )输出

str1 = 'Hello Python!'

print(str1)

# 2. 定义第二个字符串Let‘s go并使用print( )输出

str2 = "Let's go"

print(str2)

# 3. 定义第三个字符串"The Zen of Python" -- by Tim Peters 并使用print( )输出

str3 = " \"The Zen of Python\" -- by Tim Peters"

print(str3)



# # 练习二 字符串基本操作
#
# 1. 定义两个字符串分别为 xyz 、abc

str_a = 'xyz'
str_b = 'abc'

# 2. 对两个字符串进行连接

print(str_a + str_b)

# 3. 取出xyz字符串的第二个和第三个元素

print('xyz字符串的第二个元素是 %s ' % str_a[1])
print('xyz字符串的第三个元素是 %s ' % str_a[2:])

# 4. 对abc输出10次

for i in range(10) :
print('输出 %s 第 %i 次' %(str_b,i+1))

# 5. 判断a字符(串)在 xyz 和 abc 两个字符串中是否存在,并进行输出

if 'a' in str_a :
print('a字符(串)在 xyz ')
elif 'a' in str_b :
print('a字符(串)在 abc ')

# # 练习三 列表的基本操作
#
# 1.定义一个含有5个数字的列表

a_list = [1,2,3,4,5]

print(a_list)

#
# 2.为列表增加一个元素
# 100

a_list.append(100)

print(a_list)

#
# 3.使用remove() 删除一个元素后观察列表的变化

a_list.remove(1)

print(a_list)

#
# 4.使用切片操作分别取出列表的前三个元素,取出列表的最后一个元素

print('列表的前三个元素',a_list[:3])
print('列表的最后一个元素',a_list[-1])