Browse Source

teil11

teil11 Upload
develop
raspithek 2 years ago
parent
commit
535087c248
  1. 6
      create_datetime.py
  2. 9
      currentdate.py
  3. 10
      formatted_date.py
  4. 34
      zeitmessung.py

6
create_datetime.py

@ -0,0 +1,6 @@
from datetime import datetime
datum = datetime.strptime('12.12.2002 05:45', '%d.%m.%Y %M:%H')
print(datum)

9
currentdate.py

@ -0,0 +1,9 @@
from datetime import datetime
heute = datetime.now()
print(type(heute))
print(heute)
print(heute.time())
print(heute.date())

10
formatted_date.py

@ -0,0 +1,10 @@
from datetime import datetime
heute = datetime.now()
print(type(heute))
print(heute.strftime('%c %X'))
print(heute.time().strftime('%X'))
print(heute.date().strftime('%x'))
print(heute.strftime('%d.%m.%y %H:%M'))

34
zeitmessung.py

@ -0,0 +1,34 @@
from timeit import default_timer as timer
import time
def calc_square(numbers, verbose=False):
for n in range(1,numbers):
q= n*n
if verbose:
print(f'\n{n} ^ 2 = {q}')
time.sleep(0.1)
def calc_cube(numbers,verbose=False):
for n in range(1,numbers):
k = n*n*n
if verbose:
print(f'\n{n} ^ 3 = {k}')
time.sleep(0.1)
start = timer()
calc_square(100,True)
calc_cube(100,True)
ende = timer()
differenz = ende - start
print(f'Zeit mit print():{differenz}s')
start = timer()
calc_square(100)
calc_cube(100)
ende = timer()
differenz = ende - start
print(f'Zeit ohne print():{differenz}s')
Loading…
Cancel
Save