Advertisement
Guest User

harj13t3

a guest
Feb 28th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. # Toteuta alle aliohjelmana funktio
  2. # f: {n in N, n<11} -> N, x |-> x jos x <=5 ja x |-> 10 -x jos x > 5
  3.  
  4. def funktio(input):
  5.     if (isinstance(input, int) and input >= 0):
  6.         if (input <= 5):
  7.             y = input
  8.         if (input > 5):
  9.             y =  10 - input
  10.     else:
  11.         y = 'Alkio ei kuulu funktion määrittelyjoukkoon'
  12.  
  13.     return y
  14.  
  15. #
  16. # Pääohjelma
  17. #
  18. # Kutsu funktiota argumentilla -5 <= x < 11 ja sijoita
  19. # funktion arvo muuttujaan y
  20.  
  21. for x in range(-5,11):
  22.  
  23.     y = funktio(x)
  24.  
  25.     # Älä muuta alla olevaa print-komentoa, jotta kone
  26.     # osaa tarkastaa vastauksesi.
  27.  
  28.     print('x: {:3d}, f(x): {}'.format(x, y))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement