Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Toteuta alle aliohjelmana funktio
- # f: {n in N, n<11} -> N, x |-> x jos x <=5 ja x |-> 10 -x jos x > 5
- def funktio(input):
- if (isinstance(input, int) and input >= 0):
- if (input <= 5):
- y = input
- if (input > 5):
- y = 10 - input
- else:
- y = 'Alkio ei kuulu funktion määrittelyjoukkoon'
- return y
- #
- # Pääohjelma
- #
- # Kutsu funktiota argumentilla -5 <= x < 11 ja sijoita
- # funktion arvo muuttujaan y
- for x in range(-5,11):
- y = funktio(x)
- # Älä muuta alla olevaa print-komentoa, jotta kone
- # osaa tarkastaa vastauksesi.
- print('x: {:3d}, f(x): {}'.format(x, y))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement