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

2.3程序設計基本知識 實踐活動及練習 2021—2022學年人教_中圖版(2019)高中信息技術必修1

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

2.3程序設計基本知識 實踐活動及練習 2021—2022學年人教_中圖版(2019)高中信息技術必修1

資源簡介

2.3程序設計基本知識
P60實踐活動
編程計算體重指數程序設計答案:
a=float(input('請輸入身高米:'))
b=float(input('請輸入體重千克:'))
BMI=b/(a*a)
print("體重指數BMI=",round(BMI,2)) #保留1位小數
P63實踐活動
評定體重指數等級程序設計答案:
第2題:方案一
b=float(input('請輸入身高米:'))
c=float(input('請輸入體重千克:'))
bmi=c/pow(b,2)
t=bmi
print("你的體重指數BMI的值是:",round(t,1))
if t>=16.5 and t<=23.3:
print("正常")
else :
if t<=16.4:
print('低體重')
else:
if t>=23.3 and t<=26.3:
print("超重")
else:
print("肥胖")
方案二:多分支結構
b=float(input('請輸入身高米:'))
c=float(input('請輸入體重千克:'))
bmi=c/(b*b)
t=bmi
print("體重指數BMI的值是:",round(t,1))
if t>=16.5 and t<=23.3:
print("正常")
elif t<=16.4:
print('低體重')
elif t>=23.3 and t<=26.3:
print("超重")
else:
print("肥胖")
第3題:
a=input('請輸入性別:')
e='男'
f="女"
if a!=e and a!=f:
print("性別輸入錯誤")
else:
b=float(input('請輸入身高米:'))
c=float(input('請輸入體重千克:'))
bmi=c/pow(b,2)
t=bmi
if a==e:
if t>=16.5 and t<=23.3:
print("正常")
elif t<=16.4:
print('低體重')
elif t>=23.3 and t<=26.3:
print("超重")
else:
print("肥胖")
else:
if a==f:
if t>=16.5 and t<=22.7:
print("正常")
else:
if t<=16.4:
print('低體重')
else:
if t>=22.8 and t<=25.2:
print("超重")
else:
print("肥胖")
P67實踐活動
對多名學生進行體重指數的等級判斷的程序設計。
i=1
rs=int(input('請輸入學生人數:'))
while i<=rs:
i=i+1
a=input('請輸入性別:')
e='男'
f="女"
if a!=e and a!=f:
print("性別輸入錯誤")
else:
b=float(input('請輸入身高米:'))
c=float(input('請輸入體重千克:'))
bmi=c/pow(b,2)
t=bmi
print("體重指數BMI的值是:",round(t,1))
if a==e:
if t>=16.5 and t<=23.3:
print("正常")
elif t<=16.4:
print('低體重')
elif t>=23.3 and t<=26.3:
print("超重")
else:
print("肥胖")
else:
if a==f:
if t>=16.5 and t<=22.7:
print("正常")
else:
if t<=16.4:
print('低體重')
else:
if t>=22.8 and t<=25.2:
print("超重")
else:
print("肥胖")
P69練習提升
1、分別指出下面程序中循環體執行的次數,寫出運行結果,分析程序功能。
(1)
i=100
r=1 #執行次數
while i>1:
print("進入第",r,"次循環,r=",r)
r=r+1
if i%13==0:
break
i=i-1
print(i)
答案:程序執行的次數為10次,輸出i的值為91。
(2)
r=1 #執行次數
for i in range(100,1,-1):
print("進入第",r,"次循環,r=",r)
r=r+1
if i%13!=0:
continue
print(i)
答案:程序執行的次數為99,出i的值為91、78、65、52、39、26、13。
2.設計算法編寫程序實現如下功能:
已知一元二次方程ax2 +bx+c=0,從鍵盤輸入a、b和c的值,獲取該一元二次方程解的情況。
import math
a = float(input("請輸入a的值:"))
b = float(input("請輸入b的值:"))
c = float(input("請輸入c的值:"))
if a != 0:
delta = b ** 2 - 4 * a * c
if delta < 0:
print("方程無解")
elif delta == 0:
s = -b / (2 * a)
print("兩根相等:x=",s)
else :
root = sqrt(delta)
x1 = (-b + root) / (2 * a)
x2 = (-b - root) / (2 * a)
print("x1=", x1, "\t", "x2=", x2)
3.求任意兩個正整數的最大公約數,直至用戶輸入”q”或”Q”才退出程序。
while True:
a = int(input("輸入第一個正整數:"))
b = int(input("輸入第一個正整數:"))
while b:
x = a % b
a = b
b = x
print("兩個數的最大公約數是:",a)
c = input("是否繼續?(退出程序請輸入‘q’或‘Q’;按其它鍵則繼續)")
if c == "q" or c == "Q":
break
4.編寫程序和計算機來一場有趣的猜數游戲。要求:由計算機隨機生成一個100以內的正整數,用戶有五次猜數機會,如果猜中提示”猜中了!“并退出程序;否則,提示”數偏大“或”數偏小“,然后繼續猜數。如果5次均未猜中,屏幕顯示計算機隨機生成的整數,并換行給出提示“五次沒有猜中,很遺憾,游戲結束“,退出程序。
import random
number = 5
secret = random.randint(1, 100)
while number > 0:
temp1 = int(input("輸入一個整數(1-100):"))
if temp1 == secret:
print("猜中了!")
break
elif temp1 > secret:
print("數偏大,還剩", number - 1, "次機會")
else:
print("數偏小,還剩", number - 1, "次機會")
number -= 1
if number == 0:
print("答案是", secret)
print("5次沒有猜中,很遺憾,游戲結束")

展開更多......

收起↑

資源預覽

    <track id="r4fhd"></track>

    <pre id="r4fhd"><abbr id="r4fhd"><code id="r4fhd"></code></abbr></pre>
      <ul id="r4fhd"></ul>

        <menu id="r4fhd"></menu>
        1. 主站蜘蛛池模板: 伽师县| 和田市| 巴青县| 舟曲县| 上思县| 平利县| 晴隆县| 贡觉县| 铜梁县| 永定县| 二手房| 双桥区| 凤城市| 名山县| 沙河市| 侯马市| 娄底市| 佛山市| 新田县| 崇州市| 宁乡县| 宣汉县| 阜康市| 达日县| 甘谷县| 聂拉木县| 德钦县| 和平县| 林口县| 新河县| 剑阁县| 松阳县| 安多县| 连江县| 宣威市| 新平| 巴马| 台南市| 定西市| 定日县| 惠州市|