Computer Science
Write a program using user-defined function to calculate and display average of all the elements in a user-defined tuple containing numbers.
Python
Python Functions
6 Likes
Answer
def calculate_average(num):
total = 0
for element in num:
total += element
average = total / len(num)
return average
n = eval(input("Enter the tuple: "))
average = calculate_average(n)
print("The average of the elements in the tuple is:", average)
Output
Enter the tuple: (2, 4, 6, 8, 10)
The average of the elements in the tuple is: 6.0
Answered By
2 Likes
Related Questions
Write a method EvenSum(NUMBERS) to add those values in the tuple of NUMBERS which are even.
Write a function countNow(PLACES) in Python, that takes the dictionary, PLACES as an argument and displays the names (in uppercase) of the places whose names are longer than 5 characters. For example, Consider the following dictionary:
PLACES = {1: "Delhi", 2: "London", 3: "Paris", 4: "New York", 5:"Doha"}
The output should be:
LONDON
NEW YORKName the built-in mathematical function/method:
(a) Used to return an absolute value of a number.
(b) Used to return the value of xy, where x and y are numeric expressions.
(c) Used to return a positive value of the expression in float.
Name the built-in String function:
(a) Used to remove the space(s) from the left of the string.
(b) Used to check if the string is uppercase or not.
(c) Used to check if the string contains only whitespace characters or not.