Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/user/bin/env python 3.1
- from sys import argv
- from sys import exit
- import random
- import math
- import os
- os.system('clear')
- def czy_pierwsza(liczba):
- l=int(liczba)
- if l < 2:
- return False
- else:
- return all(l%i for i in range(2, int(math.sqrt(l) +1)) )
- #1__________________________________________
- def zad_1():
- print("Zadanie 1: ")
- if len(argv)!=2:
- print("Podaj jeden parametr")
- exit()
- licz=argv[1]
- if not licz.isdigit():
- print("Podaj liczbe")
- exit
- print("Czy liczba", licz,"jest liczba pierwsza:", czy_pierwsza(licz))
- #2__________________________________________
- def zad_2():
- print("Zadanie 2: ")
- slownik={}
- while len(slownik)<50:
- temp=random.randrange(0,100)
- if temp not in slownik:
- slownik[temp]=czy_pierwsza(temp)
- print(len(slownik))
- print(slownik)
- #3_________________________________
- def zad_3():
- print("Zadanie 3: ")
- list_rand=[random.randrange(20) for i in range(100)]
- #print("Lista rand:",list_rand)
- slow_n={}
- slow_p={}
- for i in range(20):
- if i%2==0:
- slow_p[i]=[j for j, x in enumerate(list_rand) if x == i]
- else:
- slow_n[i]=[j for j, x in enumerate(list_rand) if x == i]
- print("Parzyste: ",slow_p)
- #print("Nieparzyste: ",slow_n)
- slow_new={}
- for key in slow_p:
- if all(i%3 for i in slow_p[key]):
- slow_new[key]=(max(slow_p[key]),min(slow_p[key]))
- else:
- slow_new[key]=[i for i in slow_p[key] if not i%3]
- print("Nowa lista:", slow_new)
- #4__________________________________________
- def zad_4():
- print("Zadanie 4: ")
- if len(argv)!=2:
- print("Podaj jeden parametr")
- exit()
- if not argv[1].isdigit():
- print("Podaj liczbe")
- exit
- size=int(argv[1])
- slownik={i:random.randrange(2,15) for i in range(size)}
- print("Slownik:",slownik)
- slownik_odw={w:k for k,w in slownik.items()}
- print("Slownik odwrocony:",slownik_odw)
- lista=[(k,w) for k,w in slownik_odw.items()]
- lista.append(slownik_odw)
- print("Lista", lista)
- #5_________________________________
- def zad_5():
- print("Zadanie 5: ")
- list_rand=[random.randrange(0, 11) for i in range(100)]
- print("Lista rand:",list_rand)
- slow={}
- for i in range(11):
- slow[i]=[j for j, x in enumerate(list_rand) if x == i]
- print("Slownik:", slow)
- #6_________________________________
- def zad_6():
- print("Zadanie 6: ")
- size=10
- slow1={i:random.randrange(1,100) for i in range(size)}
- slow2={i:random.randrange(1,100) for i in range(size)}
- slow1_od={w:k for k,w in slow1.items()}
- slow2_od={w:k for k,w in slow2.items()}
- print("Slownik 1:",slow1)
- print("Slownik 2:",slow2)
- print("Slownik 1 odwrocony:",slow1_od)
- print("Slownik 2 odwrocony:",slow2_od)
- #for i in slow1_od:
- # if i in slow2_od:
- # slow_n[i]=(slow1_od[i],slow2_od[i])
- slow_n={k:(slow1_od[k],slow2_od[k]) for k in slow1_od if k in slow2_od}
- print(slow_n)
- #main________________________________
- #zad_1()
- #zad_2()
- #zad_3()
- #zad_4()
- #zad_5()
- zad_6()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement