LevT

Platinum Member | Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору Here's the equivalent Python code for your C program: import time import math def main(): starttime = time.time() # Code to time for i in range(1, 20000001): elapsedtime = math.sin(1.0) + math.cos(1.0) # endtime = time.time() elapsedtime = endtime - starttime print(f"Elapsed time is {elapsedtime:.2f} seconds.") print(int(endtime - starttime)) if __name__ == "__main__": main() Explanation: time.time() is used to get the current time in seconds since the epoch, which is similar to time(&starttime) and time(&endtime) in C. The loop for i in range(1, 20000001) is equivalent to the C loop for (i = 1; i <= 20000000; i++). math.sin and math.cos from the math module are used for the trigonometric calculations. print is used to output the elapsed time and the difference between endtime and starttime. Note that in Python, time.time() returns a floating-point number, so the difference is already in seconds with fractional parts. Цитата: есть ещё .for и .pas -- если надо, что для транспилятора легче? | не знаю, вероятно пофиг | Всего записей: 18039 | Зарегистр. 14-10-2001 | Отправлено: 15:30 20-05-2024 | Исправлено: LevT, 15:30 20-05-2024 |
|