1

I am writing a python code that returns me the larger of two inputs.

def bigger_num(a, b):
    if a < b:
        print ("First number is smaller than the second number.")
    elif a > b:
        print ("First number is greater than the second number.")
    else:
        print ("Two numbers are equals.")
        
a = input("Enter first number: ")
a = float(a)

b = input("Enter second number : ")
b = float(b)
print(bigger_num(a, b))

Result:
Enter first number: 19
Enter second number : 9
First number is greater than the second number.
None

How do I display the numeric result (a/b) in the print?

Ideal solution example: First number, 19 is greater than the second number

Also, is there a way to remove none from the print result?

3
  • Simplest: print ("First number", a, "is smaller than the second number", b) Commented Dec 13, 2020 at 17:54
  • You need to look for a python beginners course... but good luck and welcome to Python! Commented Dec 13, 2020 at 17:54
  • 1
    Just call bigger_num(a, b) without surrounding print. Commented Dec 13, 2020 at 17:54

1 Answer 1

2

You can use the format() method or simply concatenate the number to display it. To remove the None, just call the function without the wrapping it with a print() because you print the output inside the function

def bigger_num(a, b):
    if a < b:
        print ("First number, {0} is smaller than the second number.".format(a))
    elif a > b:
        print ("First number, {0} is greater than the second number.".format(a))
    else:
        print ("Two numbers are equals.")
        
a = input("Enter first number: ")
a = float(a)

b = input("Enter second number : ")
b = float(b)
bigger_num(a, b)

Sign up to request clarification or add additional context in comments.

1 Comment

From python 3.6 you can use f strings. In this example, f"First number, {a} is smaller than the second number." for the first conditional.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.