بخشی از مجموعه

Several example codes

~1 دقیقه مطالعه • بروزرسانی ۲۱ مهر ۱۴۰۴

Program Overview

This Python program defines a 10-element array where each element is displaced m units to the right.
Each element's position is calculated as index × m, simulating uniform motion or spacing.


Python Code:


def define_positions(m: int, count: int = 10) -> list[int]:
    return [i * m for i in range(count)]

# Read initial displacement value
m = int(input("Enter initial displacement (m): "))

# Define array of positions
positions = define_positions(m)

# Display result
print("Array of rightward positions:")
print(" ".join(map(str, positions)))

Sample Output:


Input: m = 5  
Output:  
Array of rightward positions:  
0 5 10 15 20 25 30 35 40 45

نوشته و پژوهش شده توسط دکتر شاهین صیامی