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

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

對(duì)包含變量的段落進(jìn)行文本換行

對(duì)包含變量的段落進(jìn)行文本換行

慕后森 2023-07-18 15:17:38
所以我有以下代碼:animal = str(input("A prey animal (singular): "))habitat = str(input("A habitat, such as savannah or rainforest: "))action_verb = str(input("A motion related action verb (ending with ing) such as moving or running: "))onomatopeia = str(input("A sound an animal makes, such as growl or bark: "))number_1 = int(input("An integer between 2 and 9: "))predators = str(input("A predator that eats your prey animal (plural): "))insects = str(input("A terrible swarming insect that lives in your chosen habitat (plural): "))number_2 = number_1**number_1*100print("\tAlong came a", animal, action_verb, "through the", habitat + ". All of a sudden,"     "\nthere was a loud", onomatopeia, "and the", animal, "looked around for a good place to"     "\nhide. There was a pack of", number_1, predators, "coming right towards the poor", animal+     ". However, \nall of the", predators, "had to run, because", number_2, insects, "were"    "swarming the\n", predators, "and they had to hightail it out "    "of there. \n\"Phew, that's a relief,\" thought the", animal + ", \"man, I really could"     "have \nbeen toast if not for those", insects + ".\"")我真的不知道在這里要做什么,因?yàn)橛捎谧兞康脑?,我無(wú)法將其輸出到每行設(shè)置為 80 個(gè)字符的段落中。我知道有一個(gè) textwrap 模塊,但它只適用于我嘗試過(guò)的字符串。有誰(shuí)知道我如何才能在輸出時(shí)很好地格式化它?
查看完整描述

3 回答

?
小怪獸愛(ài)吃肉

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

您可以使用 textwrap,但首先將其格式化為:"This variable {} is in the sentence".format(variable)



查看完整回答
反對(duì) 回復(fù) 2023-07-18
?
蕪湖不蕪

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

這是另一個(gè)格式化系統(tǒng)。

print(f"{current_variable} said hello!")

當(dāng) current_variable 是James它的格式字符串時(shí)

"James said hello!"


查看完整回答
反對(duì) 回復(fù) 2023-07-18
?
慕村225694

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

您可以使用更新的 f 字符串:

print(f"\t有一個(gè),{動(dòng)物},{action_verb},穿過(guò),{棲息地}。突然間,.....等等"


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

添加回答

舉報(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)