Python 3.13.7 (tags/v3.13.7:bcee1c3, Aug 14 2025, 14:15:11) [MSC v.1944 64 bit (AMD64)] on win32
Enter "help" below or click "Help" above for more information.
def generate_pulse_signal(amplitude, pulse_duration, period, num_samples, filename):
    signal = []
    
    with open(filename, 'w') as file:
        for i in range(num_samples):
            # Определение позиции в периоде
            position_in_period = i % period
            
            # Генерация импульса
            if position_in_period < pulse_duration:
                value = amplitude
            else:
                value = 0
            
            signal.append(value)
            file.write(f"{value}\n")
    
    return signal

if __name__ == "__main__":
    pulse_signal = generate_pulse_signal(
        amplitude=5.0, 
        pulse_duration=3, 
...         period=10, 
...         num_samples=30, 
...         filename="iz.txt"
...     )
...     print(f"Сгенерировано {len(pulse_signal)} отсчетов импульсного сигнала")
... 
...     
Сгенерировано 30 отсчетов импульсного сигнала
>>> print("Первые 10 строк из файла:")
...     with open("iz.txt", 'r') as file:
...         for i, line in enumerate(file):
...             if i < 10:
...                 print(f"Строка {i+1}: {line.strip()}")
...             else:
...                 break
...             
SyntaxError: multiple statements found while compiling a single statement
>>> print("Первые 10 строк из файла:")
Первые 10 строк из файла:
>>> with open("pulse_signal.txt", 'r') as file:
...     for i, line in enumerate(file):
...         if i < 10:
...             print(f"Строка {i+1}: {line.strip()}")
...         else:
...             break
... 
...         
Traceback (most recent call last):
  File "<pyshell#6>", line 1, in <module>
    with open("pulse_signal.txt", 'r') as file:
FileNotFoundError: [Errno 2] No such file or directory: 'pulse_signal.txt'
>>> with open("iz.txt", 'r') as file:
...     for i, line in enumerate(file):
...         if i < 10:
...             print(f"Строка {i+1}: {line.strip()}")
...         else:
...             break
... 
...         
Строка 1: 5.0
Строка 2: 5.0
Строка 3: 5.0
Строка 4: 0
Строка 5: 0
Строка 6: 0
Строка 7: 0
Строка 8: 0
Строка 9: 0
Строка 10: 0
