SHARE
TWEET

Forelesning, 21.10.19

evenjc Oct 22nd, 2019 (edited) 120 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # MATTEBOKS
  2. def adderer(a, b):
  3.     return a+b
  4.    
  5.  
  6. def multiplikator(a, b):
  7.     return a*b
  8.  
  9.  
  10. # CONSTRAINER
  11. import random
  12.  
  13. def constrainer(val, minimum, maximum):
  14.     if val > maximum:
  15.         val = maximum
  16.     elif val < minimum:
  17.         val = minimum
  18.        
  19.     return val
  20.    
  21.  
  22. for i in range(0,100):
  23.     rng = random.randInt(-200, 200)
  24.    
  25.     constrained_number = constrainer(rng, -50, 50)
  26.    
  27.     print(constrained_number)
  28.  
  29.  
  30. # FILE IO
  31. def writer():
  32.     file = open("min_fil.txt", "w")
  33.    
  34.     for counter in range(0,100):
  35.         file.write(str(counter) + " \t Hei\n")
  36.  
  37. def reader():
  38.     file = open("min_fil.txt", "r")
  39.    
  40.     linje = file.readline()
  41.    
  42.     while linje != "":
  43.         print(linje)
  44.         linje = file.readline()
  45.        
  46.     input("Done!")
  47.    
  48. writer()
  49. reader()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top