中文字幕精品无码一区二区,成全视频在线播放观看方法,大伊人青草狠狠久久,亚洲一区影音先锋色资源

小學課后服務 Python少兒編程 入門篇:11-猜數字游戲 課件 (12張PPT)

資源下載
  1. 二一教育資源

小學課后服務 Python少兒編程 入門篇:11-猜數字游戲 課件 (12張PPT)

資源簡介

(共12張PPT)
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Cum sociis natoque tatibus et magnis dis parturient montes, nascetur ridiculus mus.
少兒編程課
猜數字游戲
判斷結構
if …:

else:

#輸入1開始游戲,輸入其它內容退出游戲
put = input("請輸入:")
if put == "1":
print("游戲開始啦!")
else:
print("退出游戲成功!")
游戲說明
print("######## 猜數字小游戲 #########")
print("# 1.開始游戲 2.任意鍵退出游戲 #")
print("##################################")
put = input("請輸入:")
if put == "1":
print("游戲開始啦!")
else:
print("退出游戲成功!")
隨機指令
random.randint():生成隨機整數
random.random():生成隨機數
隨機數的范圍[0,1)
import random
print("######## 猜數字小游戲 #########")
print("# 1.開始游戲 2.任意鍵退出游戲 #")
print("##################################")
put = input("請輸入:")
if put == "1":
s = random.randint(1, 10)
else:
print("退出游戲成功!")
隨機整數應用
while循環結構
while True:
print(10)
while …:
#需要重復執行的代碼
#退出循環的條件
循環中的代碼需要縮進4個空格
循環次數不確定時使用while循環
break
break:退出循環
無條件進入循環
...
...
while True:
t = input("猜一猜1-10之間的整數:")

字符串操作
strip():去掉字符串首尾的空格
isdigit():檢測字符串是否只由數字組成
若滿足則返回True
若不滿足則返回False
t1 = t.strip()
if t1.isdigit():
t2 = int(t1)

else:
print("Error:不是數值,請輸入整數!")
判斷應用
print("第%s位同學"%1)
for i in range(4):
print("第%s位同學"%(i+1))
運行結果:
第1位同學
第2位同學
第3位同學
第4位同學
%s:格式化字符串
格式化字符串
猜數字游戲
...
...
...
...
...
...
if t2 > s:
print("數字比%s小" % (t2))
elif t2 < s:
print("數字比%s大" % (t2))
else:
print("數是%s,你居然猜中了^_^ 游戲結束!" % s)
break

展開更多......

收起↑

資源預覽

<pre id="tfb94"><li id="tfb94"></li></pre>

<bdo id="tfb94"><rt id="tfb94"></rt></bdo>
  • <menu id="tfb94"><dl id="tfb94"></dl></menu><i id="tfb94"><acronym id="tfb94"><sub id="tfb94"></sub></acronym></i>

    1. 主站蜘蛛池模板: 奉贤区| 台中市| 峨山| 巫溪县| 罗城| 二连浩特市| 依兰县| 筠连县| 金秀| 蒙自县| 西和县| 吉隆县| 阳江市| 南陵县| 赤峰市| 桂林市| 荥阳市| 庆元县| 云龙县| 黑龙江省| 扬中市| 汉源县| 桑日县| 延庆县| 萝北县| 句容市| 宁明县| 雅安市| 岗巴县| 甘谷县| 哈密市| 平果县| 陆河县| 缙云县| 舒城县| 双江| 绥芬河市| 牟定县| 明星| 丹东市| 绍兴市|