Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
lesson11_2
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
cf1c69af
authored
Nov 12, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
7eaed43a
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
0 deletions
cnm.py
cnm.py
0 → 100644
View file @
cf1c69af
def
new_input
():
#定义函数new_input()
total
=
[]
#新建列表total
while
True
:
#无限循环
price
=
input
(
"请输入价格"
)
#输入的整数赋值给price变量
try
:
#尝试下面的语句 捕捉异常
p
=
int
(
price
)
#将price转换为整数类型
except
:
#如果语句出错 就执行下面的
print
(
"请输入一个整数"
)
#输入提示整数
else
:
#如果没出错 就执行下面的
total
.
append
(
p
)
#在total列表后面加元素p
if
price
==
'q'
:
#如果变量=q就执行下面语句
break
#终止循环
#print(total) #输出列表全部元素
print
(
'-'
*
30
)
#输出30个下划线
return
total
t
=
new_input
()
print
(
t
)
#调用函数
\ No newline at end of file
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