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

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

我是否讓我的代碼對(duì)我自己來(lái)說(shuō)太復(fù)雜了?

我是否讓我的代碼對(duì)我自己來(lái)說(shuō)太復(fù)雜了?

Go
慕勒3428872 2023-02-22 15:05:36
我目前仍在學(xué)習(xí) Python 的基礎(chǔ)知識(shí)。我看到其他人將攝氏度轉(zhuǎn)換為華氏度,這就像 10 行。雖然我的代碼超過(guò) 40 行。我沒(méi)有完全理解'返回'的意義是什么,所以我選擇了一個(gè)簡(jiǎn)單的項(xiàng)目來(lái)理解它。但是當(dāng)我意識(shí)到我的代碼對(duì)于如此簡(jiǎn)單的事情來(lái)說(shuō)太長(zhǎng)了。感覺(jué)我應(yīng)該做很多困難的項(xiàng)目,因?yàn)槲以诤?jiǎn)單的事情上使用了很多行。對(duì)不起,我是新手,我很想通過(guò)做項(xiàng)目來(lái)學(xué)習(xí)。困難的初學(xué)者項(xiàng)目的任何建議都會(huì)有所幫助。謝謝!import timedegree_sign = u'\N{DEGREE SIGN}'def fahrenheit():    degree = int(input('\nHow many degrees is it currently in Fahrenheit?: '))    a = round((degree - 32) * 5/9)        return adef celsius():    degree = int(input('\nHow many dgrees is it currently in Celsius?: '))    a = round((degree * 9/5) + 32)        return aprint("Welcome to my first weather conversion!\n")weather = input('Do you want to convert to Fahrenheit or Celsius (c/f)? \n').lower()if weather == "c":    time.sleep(0.5)    print(f'It is currently {fahrenheit()}{degree_sign}C.')elif weather == "f":    time.sleep(0.5)    print(f'\nIt is currently {celsius()}{degree_sign}F.')else:    while True:        print("\nI'm sorry I don't understand.\n")        weather = input('Do you want to convert to Fahrenheit or Celsius (c/f)? \n').lower()        if weather != "c" and weather != "f":            continue        elif weather == "c":            time.sleep(0.5)            print(f'\nIt is currently {fahrenheit()}{degree_sign}C')            break        elif weather == "f":            time.sleep(0.5)            print(f'\nIt is currently {celsius()}{degree_sign}F.')            break
查看完整描述

1 回答

?
楊__羊羊

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

import time


degree_sign = u'\N{DEGREE SIGN}'


def fahrenheit():

    degree = int(input('\nHow many degrees is it currently in Fahrenheit?: '))

    a = round((degree - 32) * 5/9)

    

    return a


def celsius():

    degree = int(input('\nHow many dgrees is it currently in Celsius?: '))

    a = round((degree * 9/5) + 32)

    

    return a


print("Welcome to my first weather conversion!\n")


weather = input('Do you want to convert to Fahrenheit or Celsius (c/f)? \n').lower()

d = {"c": f"{fahrenheit()}{degree_sign}C",

     "f": f"{celsius()}{degree_sign}F"}


if weather == "c":

    time.sleep(0.5)

    print(f'It is currently {fahrenheit()}{degree_sign}C.')


elif weather == "f":

    time.sleep(0.5)

    print(f'\nIt is currently {celsius()}{degree_sign}F.')


else:

    while True:

        print("\nI'm sorry I don't understand.\n")

        weather = input('Do you want to convert to Fahrenheit or Celsius (c/f)? \n').lower()

        try:

            time.sleep(0.5)

            print("It is currently ", d[weather])

        except:

            continue

同樣可以修改其他if-else子句


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

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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