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

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

循環(huán)以添加更多輸入

循環(huán)以添加更多輸入

LEATH 2022-09-06 17:30:53
我還有3輛車(chē),但我需要知道如何循環(huán)諸如汽車(chē)輸入之類(lèi)的東西,這樣如果你對(duì)附加功能做了錯(cuò)誤的輸入,它將允許你再次輸入它,所以它們必須是1或0。print("===================================================") print("==============Car Finance Calculations=============") print(" Choose your veicle: ")print(" SUV type 1 ")print(" Hatch type 2 ")print(" Sedan type 3 ")print("===================================================")caaaaaaaar = int(input(" Please enter Which car you want to finance: "))years = int(input(" enter years of loan either 3 or 4 or 5 Years: "))      if caaaaaaaar == 1:                                                 carsvalue = int(input("Please enter you cars value: "))        residual = carsvalue * 0.30                                                   financing = carsvalue - residual                                print(" financing value for the car is: ", round(financing,2))          print(" Intrest rate is 9% ")                                   n = years * 12                                                  r = 9 / (100 * 12)                                             Financingcost = financing * ((r*((r+1)**n))/(((r+1)**n)-1))     print(" Your Montly financing rate is: ", round(Financingcost,2))        print("================================================================================")    print("Please Choose extras: ")                                       print("======================================================")    print(" If you would like fuel type 1 if not type 0")    print(" If you would like insurance type 1 if not type 0")    print(" if you would like Maintenance type 1 if not type 0")
查看完整描述

4 回答

?
梵蒂岡之花

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

您希望使用 while 循環(huán)。喜歡這個(gè):


carsEntered = 0

while (carsEntered <= 4):

    caaaaaaaar = int(input(" Please enter Which car you want to finance: "))

    years = int(input(" enter years of loan either 3 or 4 or 5 Years: "))

    carsEntered += 1

您也可以改用循環(huán),但這取決于您要執(zhí)行的操作。for


查看完整回答
反對(duì) 回復(fù) 2022-09-06
?
搖曳的薔薇

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

根據(jù)我對(duì)問(wèn)題的理解,您希望運(yùn)行迭代,直到用戶(hù)給出正確的答案。


在這種情況下,可以在 中使用 標(biāo)志變量。while


flag = False

while(flag is False):

    if(condition_statisfied):

        flag = True


查看完整回答
反對(duì) 回復(fù) 2022-09-06
?
楊魅力

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

我的建議是采取一種功能性方法來(lái)解決這個(gè)問(wèn)題。您正在多次調(diào)用,并希望在每次繼續(xù)下一行之前驗(yàn)證用戶(hù)輸入。您可以在一個(gè)函數(shù)中執(zhí)行此操作,該函數(shù)將繼續(xù)循環(huán),直到確認(rèn)輸入有效。驗(yàn)證輸入后,可以通過(guò)使用關(guān)鍵字返回值來(lái)退出函數(shù)的幀。int(input())return


# This is the function definition. 

# The code in this function does not execute until the function is called.

def prompt_int(

        text,

        minimum=0,

        maximum=1,

        error="The value you entered is not valid try again."

):

    # when the function is called it will start a second while loop that will keep looping

    # until valid input is entered

    while True:

        try:

            val = int(input(text))

            if minimum <= val <= maximum:

                return val

            raise ValueError

        except ValueError:

            print(error)



# This is the outer while loop. It will keep looping forever if the user so chooses.

while True:

    # instead of calling print() a bunch one option is to assign a docstring to a variable

    car_prompt = '''

===================================================

==============Car Finance Calculations=============

Choose your veicle:

SUV: 1

Hatch: 2

Sedan: 3

===================================================

Please enter the number for the car you want to finance or 0 to exit:\n

'''

    # This is where we first call the function. 

    # Our docstring will be passed into the function to be used as a prompt.

    # We also pass in some args for maximum and minimum params

    caaaaaaaar = prompt_int(car_prompt, 0, 3)

    # 0 is false so we can exit the while loop if the user enters 0

    if not caaaaaaaar:

        break

    year_prompt = "Enter years of the car loan (3, 4 or 5):\n"

    years = prompt_int(year_prompt, 3, 5)


    if caaaaaaaar == 1:

        val_prompt = "Please enter you cars value:\n"

        carsvalue = prompt_int(val_prompt, 0, 2147483647)

        residual = carsvalue * 0.30

        financing = carsvalue - residual


        print("Financing value for the car is: ", round(financing, 2))

        print("Intrest rate is 9% ")


        n = years * 12

        r = 9 / (100 * 12)

        Financingcost = financing * ((r * ((r + 1) ** n)) / (((r + 1) ** n) - 1))


        print(" Your Montly financing rate is: ", round(Financingcost, 2))

        print("================================================================================")

        print("Please Choose extras: ")

        print("======================================================")

        x = prompt_int("If you would like fuel type 1 else type 0:\n")

        y = prompt_int("If you would like insurance type 1 else type 0:\n")

        z = prompt_int("If you would like Maintenance type 1 else type 0:\n")

        print("======================================================")


        if x == 1:

            print("Yes you want fuel")

            fuelcost = 80 * 4.33

            print("fuel cost is", round(fuelcost, 2))

        else:

            print("you dont want fuel as an extra")

            fuelcost = 0

            print("Fuel cost is: ", fuelcost)


        print("=======================================")


        if y == 1:

            print("yes you want insurance")

            insurancecost = (1200 / 12)

            print("Insurance cost is: ", round(insurancecost, 2))

        else:

            print("you dont want insurance")

            insurancecost = 0

            print("insurance cost is: ", insurancecost)


        print("=======================================")


        if z == 1:

            print("yes you want maintenance")

            maintenancecost = (100 * 1)

            print("Maintenance cost is: ", round(maintenancecost, 2))

        else:

            print("you dont want maintenance")

            maintenancecost = 0

            print("maintenance cost is: ", maintenancecost)

        print("=======================================")


        total_cost_for_extras = fuelcost + maintenancecost + insurancecost

        print("Total cost for the selected extras is: ", round(total_cost_for_extras, 2))

        TOTALFOREVERYTHING = total_cost_for_extras + Financingcost

        print("Total monthly financing rate is: ", round(TOTALFOREVERYTHING, 2))

    elif caaaaaaaar == 2:

        # Put your code for car 2 in this block. 

        # If it is like car 1 code except the value of a few variables 

        # then make another func 

        pass

    else:

        # Car 3 code...

        pass


查看完整回答
反對(duì) 回復(fù) 2022-09-06
?
神不在的星期二

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

我建議你把你的車(chē)輛類(lèi)型放在字典里:


vehicle_type_dict = {

    1: "SUV type",

    2: "Hatch type",

    3: "Sedan type"

}

并執(zhí)行 while 循環(huán)以檢查您的輸入是否在字典中:


while True:

    caaaaaaaar = int(input(" Please enter Which car you want to finance: "))


    if caaaaaaaar not in vehicle_type_dict:

        continue #loop again if input not in the dictionary


    #read next line of code if input is in the dictionary


    #do something below if input is correct


    years = int(input(" enter years of loan either 3 or 4 or 5 Years: "))


    break #end loop


查看完整回答
反對(duì) 回復(fù) 2022-09-06
  • 4 回答
  • 0 關(guān)注
  • 132 瀏覽
慕課專(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)