Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
lesson4_6
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
8a1d9168
authored
Nov 06, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
ccd74dad
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
0 deletions
1.py
guess_number.py
1.py
0 → 100644
View file @
8a1d9168
num
=
0
while
num
<
20
:
if
num
%
2
==
1
:
print
(
num
)
num
+=
1
\ No newline at end of file
guess_number.py
0 → 100644
View file @
8a1d9168
import
turtle
as
x
import
random
#导入工具库
x
.
TurtleScreen
.
RUNNING
=
True
#创建一个窗口
x
.
setup
(
width
=
800
,
height
=
450
)
#设置窗口的大小尺寸
x
.
hideturtle
()
#隐藏画笔图标
x
.
color
(
"red"
)
#设置颜色
x
.
penup
()
#抬笔
x
.
setpos
(
-
350
,
0
)
#设置画笔位置
myfont
=
(
'微软幼圆'
,
26
,
'bold'
)
#设置字体
rand_number
=
random
.
randint
(
1
,
100
)
#产生游戏开始前的随机数
x
.
write
(
'我想到了一个1到100的数字,来猜猜吧!'
,
font
=
myfont
)
#设置用户提示语
guess_number
=
0
answer
=
None
#初始化猜的数字和回答的数字
#下面就是猜数字的过程
while
guess_number
!=
rand_number
:
guess_number
=
x
.
simpledialog
.
askinteger
(
'猜数字游戏'
,
'请输入一个整数'
)
if
guess_number
==
rand_number
:
answer
=
'你猜对了,游戏结束!'
elif
guess_number
>
rand_number
:
answer
=
'你猜大了,请再猜一次!'
else
:
answer
=
'你猜小了,请再猜一次!'
x
.
clear
()
x
.
write
(
answer
,
font
=
myfont
)
x
.
done
()
#保证窗口继续运行
\ 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