Home > OS >  How do I preform a print statement, while calling a function on the same line?
How do I preform a print statement, while calling a function on the same line?

Time:09-25

I am working on writing a simple program for school where I need to calculate the product of two integers inputted by the user and return the answer. I am wondering how I can print the statement below, with the answer (function) following the semicolon.

print("the product of the two integers is: ")

#Calls the function 
multiply()

Full program:

print("This program will find the product of the two integers you input.")

#Prompts user to enter the first integer they want to multiply
num_one = float(input("Enter the first number you would like to multiply: "))

#Prompts the user to enter the second integer they want to multiply
num_two = float(input("Enter the first number you would like to multiply: "))

#Function to find the product of the two numbers
def multiply():
    return num_one * num_two

print("the product of the two integers is: ")

#Calls the function 
multiply()

CodePudding user response:

As the comments have pointed out, all you need to do is,

print("the product of the two integers is: ", multiply())

However, you can simplify this to

print(f"the product of the two integers is: {num_one*num_two}")

CodePudding user response:

print("The product of the two integers is: "   str(multiply()))
  • Related