所以我有以下代碼: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 + ".\"")我真的不知道在這里要做什么,因為由于變量的原因,我無法將其輸出到每行設置為 80 個字符的段落中。我知道有一個 textwrap 模塊,但它只適用于我嘗試過的字符串。有誰知道我如何才能在輸出時很好地格式化它?
添加回答
舉報
0/150
提交
取消