Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- f = open("class.txt", "r", encoding="UTF-8") # for write the 2nd "w"
- group = []
- names = []
- # Fájlok beolvasása
- # f.readline() this would read the first line of the file
- for line in f:
- parts = line.split(";")
- names.append(parts[0])
- group.append(int(parts[1]))
- # Így definiálunk egy függvényt. f(x) = 2x + 1
- def f(x):
- x = x * 2
- return x + 1
- x = 2
- print(f(x)) # Így hívjuk meg a függvényt
- print(x)
- # Előjel függvény
- def sign(x):
- if x < 0:
- return -1
- elif x > 0:
- return 1
- else:
- return 0
- for i in range(10):
- rnd = random.randint(-10, 10)
- print(f"num: {rnd}, sign: {sign(rnd)}")
- li = [3, 6, 99, 2, 0]
- # Függvény, ami egy lista minden elemét a négyzetére emeli
- def squareli(li):
- new_list = []
- for item in li:
- new_list.append(item ** 2)
- return new_list
- print(squareli(li))
- # Függvény, ami a duplikátumokat kiszűri
- li = [1, 1, 2, 2, 3, 5, 12, 2, 1]
- def distinct(li):
- s = []
- for item in li:
- if item not in s:
- s.append(item)
- return s
- print(distinct(li))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement