103k views
4 votes
Write a program using function which accept two integers as an argument and return it sayerage. Call this function from main() and print the results in main().

1 Answer

3 votes

Final answer:

A Python program was provided that defines a function to calculate the average of two integers. It prompts the user for input, computes the average, and prints the result in the main function.

Step-by-step explanation:

The student has asked for a program that uses a function to compute the average of two integers. Below is an example in Python that accomplishes this task:



def calculate_average(num1, num2):
return (num1 + num2) / 2

def main():
first_number = int(input('Enter first integer: '))
second_number = int(input('Enter second integer: '))
average = calculate_average(first_number, second_number)
print('The average is', average)

if __name__ == '__main__':
main()



This program defines a function named calculate_average that takes two integer arguments and returns their average. The function is then called in the main function, where the user is prompted to enter the two integers. After computing the average, the result is printed out.

User Aydjay
by
8.4k points