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

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次沒有猜中,很遺憾,游戲結束")

展開更多......

收起↑

資源預覽

<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. 主站蜘蛛池模板: 分宜县| 镇沅| 辽中县| 淮安市| 施甸县| 密山市| 焦作市| 涟源市| 北海市| 茂名市| 南靖县| 遂宁市| 冕宁县| 永福县| 东乡族自治县| 迁安市| 木里| 定安县| 襄城县| 寻甸| 炉霍县| 阿鲁科尔沁旗| 锡林浩特市| 永胜县| 霍州市| 锦州市| 苏尼特左旗| 卢氏县| 呼玛县| 额尔古纳市| 株洲县| 成武县| 盱眙县| 张掖市| 武强县| 赤壁市| 锦屏县| 石渠县| 黔西县| 阳城县| 通山县|