Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/user/bin/env python 3.4
- from sys import argv
- import math
- import random
- import os
- os.system('clear')
- def isPalindrome(liczba):
- stri_licz=str(liczba)
- pol_dl=math.floor(len(stri_licz)/2)
- for i in range(pol_dl):
- if stri_licz[i] != stri_licz[-i-1]:
- return False
- return True
- #1_________________________________
- def zad_1():
- print("Zadanie 1: ")
- if len(argv)==1:
- print("Za malo elementow")
- raise SystemExit
- print(argv[1], "jest polindromem: ",isPalindrome(argv[1]))
- #2_________________________________
- def zad_2():
- print("Zadanie 2: ")
- slow={}
- for i in range(100):
- temp=random.randint(100,10000)
- if temp not in slow:
- slow[temp]=isPalindrome(temp)
- print (slow)
- #3_________________________________
- def zad_3():
- print("Zadanie 3: ")
- list_rand=[random.randint(0, 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)
- stat=slow_p
- print("Lista parzyste:",stat)
- for i in range(0,20,2):
- if len(stat[i])%2==0:
- mediana=( stat[i][ math.floor(len(stat[i])/2) -1 ] + stat[i][ math.floor(len(stat[i])/2) ] )/2
- else:
- mediana=stat[i][ math.floor( len(stat[i])/2 ) ]
- stat[i]=(mediana, max(stat[i]) - min(stat[i]))
- print("Lista rand ze statystyka:", stat)
- #4_________________________________
- def zad_4():
- print("Zadanie 4: ")
- if len(argv)==1:
- print("Za malo elementow")
- raise SystemExit
- elif not argv[1].isnumeric():
- print("Argv[1] nie jest liczba")
- raise SystemExit
- size=int(argv[1])
- slownik={}
- for i in range(size):
- slownik[i]=random.randint(2, 15)
- print("Slownik: ",slownik)
- lista=[(slownik[i],i) for i in slownik]
- slownik_odw={j:i for i, j in slownik.items()}
- lista.append(slownik_odw)
- print ("Lista:",lista)
- #5_________________________________
- def zad_5():
- print("Zadanie 5: ")
- max_r=11
- lista=[random.randint(0,max_r) for x in range(100)]
- print("Lista",lista)
- slownik={}
- for i in range(max_r+1):
- slownik[i]=[j for j,x in enumerate(lista) if x==i]
- print("Slownik2:", slownik)
- #6_________________________________
- def zad_6():
- print("Zadanie 6: ")
- slownik_1={i:random.randint(1,100) for i in range(10)}
- slownik_2={i:random.randint(1,100) for i in range(10)}
- print("Slownik_1:",slownik_1)
- print("Slownik_2:",slownik_2)
- slownik_1_odw={j:i for i,j in slownik_1.items()}
- slownik_2_odw={j:i for i,j in slownik_2.items()}
- print("Slownik_1 po odwrocie:",slownik_1_odw)
- print("Slownik_2 po odwrocie:",slownik_2_odw)
- slownik={}
- for key in slownik_1_odw:
- if key in slownik_2_odw:
- slownik[key]=(slownik_1_odw[key],slownik_2_odw[key])
- print("Nowy slownik z kluczami z slownik slownik_1_odw i slownik_2_odw:",slownik)
- #main_________________________________
- #zad_1()
- #zad_2()
- #zad_3()
- #zad_4()
- #zad_5()
- zad_6()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement