PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Created by Zygarde
# Problem: Sum of Even Numbers
# Write a function that takes a positive integer n as input and returns the sum of all even numbers from 1 to n.
#
# Input:
# - A single positive integer n (1 ≤ n ≤ 1000).
#
# Output:
# - An integer representing the sum of all even numbers from 1 to n.
#
# Example Runs:
#
# Example 1:
# Input: 6
# Output: 12
# (Explanation: Even numbers from 1 to 6 are 2, 4, 6. Their sum is 2 + 4 + 6 = 12)
#
# Example 2:
# Input: 10
# Output: 30
# (Explanation: Even numbers from 1 to 10 are 2, 4, 6, 8, 10. Their sum is 30)
#
# Example 3:
# Input: 1
# Output: 0
# (Explanation: There are no even numbers from 1 to 1, so the sum is 0)
Enter to Rename, Shift+Enter to Preview
OUTPUT
Uruchom