assign
This commit is contained in:
parent
a47ef094af
commit
c516afc400
13 changed files with 240 additions and 184 deletions
|
|
@ -1,30 +1,31 @@
|
|||
def analyze_numbers(numbers):
|
||||
if not numbers:
|
||||
return 0, 0, 0
|
||||
def count_words(text):
|
||||
words = text.lower().split()
|
||||
word_count = {}
|
||||
|
||||
total = sum(numbers)
|
||||
average = total / len(numbers)
|
||||
for word in words:
|
||||
word = word.strip('.,!?')
|
||||
if word in word_count:
|
||||
word_count[word] = word_count[word] + 1
|
||||
else:
|
||||
word_count[word] = 1
|
||||
|
||||
positive_count = 0
|
||||
for num in numbers:
|
||||
if num > 0:
|
||||
positive_count += 1
|
||||
return word_count
|
||||
|
||||
def find_most_common(word_count):
|
||||
most_common = None
|
||||
max_count = 0
|
||||
|
||||
return total, average, positive_count
|
||||
for word, count in word_count.items():
|
||||
if count > max_count:
|
||||
most_common = word
|
||||
max_count = count
|
||||
|
||||
return most_common, max_count
|
||||
|
||||
def get_coordinates():
|
||||
x = 10
|
||||
y = 20
|
||||
z = 30
|
||||
return x, y, z
|
||||
text = "Hello world hello there world hello"
|
||||
counts = count_words(text)
|
||||
common_word, frequency = find_most_common(counts)
|
||||
|
||||
data = [3, -1, 4, -2, 0, 5, -3]
|
||||
total, avg, positives = analyze_numbers(data)
|
||||
|
||||
print(f"Numbers: {data}")
|
||||
print(f"Total: {total}")
|
||||
print(f"Average: {avg:.2f}")
|
||||
print(f"Positive numbers: {positives}")
|
||||
|
||||
x, y, z = get_coordinates()
|
||||
print(f"\nCoordinates: x={x}, y={y}, z={z}")
|
||||
print(f"Text: {text}")
|
||||
print(f"Word counts: {counts}")
|
||||
print(f"Most common: '{common_word}' appears {frequency} times")
|
||||
Loading…
Add table
Add a link
Reference in a new issue