Python interim evaluation calculator (number)

Asked 2 years ago, Updated 2 years ago, 18 views

I'm taking a Python class, and I don't know anything, but they want me to submit it for an interim evaluation.

Can someone help me?

[Conditions]

python

2022-09-20 08:41

1 Answers

def calculator(numbers):
    if type(numbers) != "list":
        raise ValueError
    length = len(numbers)

    total = 0
    for num in numbers:
        total += num

    return length, total

# When entering a list containing numbers, 1) length of the list, 2) return the sum of the numbers
numbers = [1,2,3]
print(calculator(numbers))

# Error occurs when numbers enter str type
numbers = "1,2,3"
print(calculator(numbers))

Is there a reason for taking a lectureing? Aren't you looking at the questions to code them? Listen to the class hard :)


2022-09-20 08:41

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.