第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

嘗試在 python 中執(zhí)行余弦規(guī)則公式,但沒(méi)有給出預(yù)期的輸出

嘗試在 python 中執(zhí)行余弦規(guī)則公式,但沒(méi)有給出預(yù)期的輸出

MMTTMM 2023-08-22 10:28:56
如果我選擇缺失角度函數(shù)并輸入例如 a = 10、b = 10、c = 10,則角度的預(yù)期輸出為 60 度,但程序的輸出為 0.1546...import math, sysdef missingAngle():    sideA = int(input("size of side a = "))    sideB = int(input("size of side b = "))    sideC = int(input("size of side c = "))    answer = math.acos((sideB**2 + sideC**2 - sideA**2) / (2 * sideB * sideC))    return answerdef missingSide():    angleA = int(input("size of angle A = "))    sideB = int(input("size of side b = "))    sideC = int(input("size of side c = "))    answer = math.sqrt(sideB**2 + sideC**2 - 2 * sideB * sideC * math.cos(angleA))    return answermissingSideOrAngle = input("Are you trying to work out the missing angle or side?(Angle/Side) = ")while True:    if missingSideOrAngle.title() == "Angle":        print("Your answer is = " + str(missingAngle()))        sys.exit()    elif missingSideOrAngle.title() == "Side":        print("Your answer is = " + str(missingSide()))        sys.exit()    else:        missingSideOrAngle = input("Please enter a valid string(Angle/Side) = ")
查看完整描述

1 回答

?
偶然的你

TA貢獻(xiàn)1841條經(jīng)驗(yàn) 獲得超3個(gè)贊

我永遠(yuǎn)無(wú)法重現(xiàn)產(chǎn)生錯(cuò)誤 0.1546 的錯(cuò)誤。


這是您的程序,經(jīng)過(guò)一些調(diào)整,將幫助您擴(kuò)展程序的功能:


import math


def missingAngle():

    sideA = float(input("size of side a = "))

    sideB = float(input("size of side b = "))

    sideC = float(input("size of side c = "))

    try:

        answer = math.acos((sideB**2 + sideC**2 - sideA**2) / (2 * sideB * sideC))

        return f'Your answer is: {math.degrees(answer):.2f} degrees'

    except ValueError:

        return 'Values given cannot form a triangle'


def missingSide():

    angleA = math.radians(float(input("size of angle A (degrees) = ")))

    sideB = float(input("size of side b = "))

    sideC = float(input("size of side c = "))


    answer = math.sqrt(sideB**2 + sideC**2 - 2 * sideB * sideC * math.cos(angleA))

    return f'Your answer is: {answer:.2f} units'



while True:

    missingSideOrAngle = input("Are you trying to work out the missing angle or side?(Angle/Side) = ")

    if missingSideOrAngle.title() == "Angle":

        print(missingAngle())


    elif missingSideOrAngle.title() == "Side":

        print(missingSide())


    else:

        missingSideOrAngle = input("Please enter a valid string(Angle/Side) = ")

我將其設(shè)置為一個(gè)實(shí)際的循環(huán),因此它將讓用戶(hù)無(wú)休止地運(yùn)行場(chǎng)景,直到他們點(diǎn)擊Ctrl-C或輸入引發(fā)未處理錯(cuò)誤的內(nèi)容。我沒(méi)有嘗試解釋所有可能的錯(cuò)誤。


這missingAngle是為了返回學(xué)位。它還包含一個(gè)“try- except”塊來(lái)捕獲如果三邊不能形成真正的三角形(例如:12、45、85)時(shí)將發(fā)生的錯(cuò)誤。輸入被轉(zhuǎn)換為浮點(diǎn)數(shù),因此用戶(hù)可以輸入距離或角度的小數(shù),并且返回被格式化為呈現(xiàn)到小數(shù)點(diǎn)后兩位。


這應(yīng)該對(duì)您有所幫助。您可能需要為非數(shù)字的數(shù)字字段的用戶(hù)輸入設(shè)計(jì)錯(cuò)誤處理,并運(yùn)行一些測(cè)試以查看missingSide用戶(hù)輸入可能出現(xiàn)的問(wèn)題并捕獲這些問(wèn)題。您可能想要嘗試的一種方法是給它一個(gè) 180 度的角度。某些值可能不會(huì)產(chǎn)生實(shí)際錯(cuò)誤,但可能會(huì)產(chǎn)生意想不到的結(jié)果。


祝你好運(yùn)!


查看完整回答
反對(duì) 回復(fù) 2023-08-22
  • 1 回答
  • 0 關(guān)注
  • 100 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)