You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python编程课程作业求助:Pseudocode与Flowchart制作指导

Hey there! Let's sort this out for you

First off, great job on your code—it definitely meets all the requirements! Let's confirm:

  • You're using strings (all the input prompts, "woof"/"meow", pet names)
  • You've defined a custom function (animal())
  • You've got a loop (for letter in name)
    The logic flows nicely too, so that's a solid start.

Pseudocode for your program

Pseudocode is just plain-language "code" that focuses on logic instead of strict syntax. Here's how to translate your Python code into clear pseudocode:

START
    PROMPT user: "Do you have a dog or a cat? "
    STORE response in variable pet

    DEFINE FUNCTION animal(name, sound):
        PRINT name + " is saying hi!"
        FOR each character in name:
            PRINT sound + " ", without starting a new line

    IF pet equals "dog":
        PROMPT user: "What is your dog's name? "
        STORE response in dog_name
        CALL animal(dog_name, "woof")
    ELSE IF pet equals "cat":
        PROMPT user: "What is your cat's name? "
        STORE response in cat_name
        CALL animal(cat_name, "meow")
    ELSE:
        PRINT "Try again :("
END

Flowchart step-by-step guide

Flowcharts use simple shapes to map out your program's flow. Here's exactly how to build one for your code:

  • Start with an oval (start/end shape) labeled "Start"
  • Add a parallelogram (input/output shape) labeled "Input: Do you have a dog or a cat?" → draw an arrow from Start to this shape
  • Add a diamond (decision shape) labeled "Is input 'dog'?"
    • From "Yes" arrow:
      • Add another parallelogram: "Input: What is your dog's name?"
      • Add a rectangle (process shape): "Call animal(dog_name, 'woof')"
    • From "No" arrow:
      • Add another diamond: "Is input 'cat'?"
        • From "Yes" arrow:
          • Add parallelogram: "Input: What is your cat's name?"
          • Add rectangle: "Call animal(cat_name, 'meow')"
        • From "No" arrow:
          • Add rectangle: "Print 'Try again :('"
  • Now map the animal() function flow (attach this to the "Call animal..." rectangles):
    • Rectangle: "Print [name] is saying hi!"
    • Add a loop shape (a rectangle with a curved arrow pointing back to itself) labeled "For each letter in name:"
      • Inside the loop: Rectangle "Print [sound] + space"
    • After the loop ends, draw an arrow to an oval labeled "End"

Quick tiny optimization (optional!)

If you want to make your code more user-friendly, you can make the pet check case-insensitive. Just change the condition to:

if pet.lower() == "dog":

This way, users can input "Dog", "DOG", etc., and it still works.

内容的提问来源于stack exchange,提问作者Carl32100

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.28 06:39:18