Design a function named max that accepts two integer values as arguments and returns the value that is the greater of the two. For example, if 7 and 12 are passed as arguments to the function, the function should return 12. Use the function in a program that prompts the user to enter two integer values. The program should display the value that is the greater of the two.

NEED HELP WITH >>>>>>>>>>>>>>>>> variable lists, IPO Chart, pseudocode, Flowchart

Dani AI

Generated

is on the right track: the solution separates input, logic, and output. correctly notes that pseudocode style can vary, and ’s point about mastering simple if/then flow is valid. Below are a compact variable list and IPO chart, clear pseudocode, a textual flow description, and a short, safer Python example that avoids common pitfalls (naming collisions and invalid input).

  • Variables

    • num1 (int) — first integer input
    • num2 (int) — second integer input
    • result (int) — greater value to print
    • err (str) — validation message if parsing fails
  • IPO chart

    • Input: two integers from console
    • Process: validate inputs, determine larger value (handle equality)
    • Output: print the larger value (or a message if input invalid)

Pseudocode (concise, language-agnostic)

  • FUNCTION max_of_two(a, b)
    • IF a >= b THEN return a ELSE return b
  • FUNCTION read_integer(prompt)
    • REPEAT: prompt, try parse integer, until success
    • RETURN parsed integer
  • MAIN
    • a := read_integer("Enter integer 1:")
    • b := read_integer("Enter integer 2:")
    • result := max_of_two(a, b)
    • PRINT result

Flow (textual)
Start -> read num1 -> read num2 -> decision: is num1 >= num2? -> output chosen value -> End.
This makes a straightforward flowchart: two input nodes, one decision diamond, one output node.

def max_of_two(a: int, b: int) -> int:
    return a if a >= b else b

def read_int(prompt: str) -> int:
    while True:
        try:
            return int(input(prompt))
        except ValueError:
            print("Invalid integer; try again.")

def main() -> None:
    a = read_int("Enter first integer: ")
    b = read_int("Enter second integer: ")
    print(f"Greater number between {a} and {b} is {max_of_two(a, b)}")

if __name__ == "__main__":
    main()

Notes and troubleshooting

  • Avoid naming a function max to prevent shadowing Python’s built-in max.
  • Include input validation so non-integer entries do not crash the program.
  • Decide explicitly how ties are handled (above returns the first when equal).

Recommended Answers

All 3 Replies

The neat thing about pseudocode is it has defied hard standards. I can't guess if your class has defined it to be in some format so I'll take pseudocode to be "resembling a simplified programming language, used in program design." Since this is just resemblence and not standardized your attempt at pseudocode will do nicely. It's much like writing a book. You get better the more you do.

That's pretty low level stuff that you should be able to handle just by rereading your class notes. If you don't know how to flowchart a simple if-then structure then you've probably been sleeping in class.

What, specifically, is giving you problems?

def max(firstNumber, secondNumber):

if firstNumber > secondNumber:
    return firstNumber
else:
    return secondNumber

def getNumbersFromUser():

userFirstNumber = int(input("Please enter the first number: "))
userSecondNumber = int(input("Please entter the second number: "))
return userFirstNumber, userSecondNumber

def main():

userFirstNumber, userSecondNumber = getNumbersFromUser()
print("The maximum number between", userFirstNumber, "and", \
      userSecondNumber, "is", max(userFirstNumber, userSecondNumber))

main()

This is my program code

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.