SHARE
TWEET

Untitled

a guest Dec 10th, 2018 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Sæþór Bergsson
  2. #Prof_3
  3. #
  4. from math import *
  5. import random
  6.  
  7.  
  8. def bua_til_lista(random_min, random_max, fjoldi=100):
  9.     listi1 = []
  10.     for i in range(fjoldi):
  11.         randomtala = random.randrange(random_min, random_max)
  12.         listi1.append(randomtala)
  13.     return listi1
  14.  
  15. def syna_lista(tolulisti):
  16.     for tala in tolulisti:
  17.         print(tala,end="-")
  18. def medaltal(listi):
  19.     summalista = sum(listi)
  20.     medaltal = summalista / len(listi)
  21.     print("%.2f"%medaltal)
  22.  
  23. def deilanlegt_med_9_og_15(tolulisti):
  24.     listi2 = []
  25.     for i in tolulisti:
  26.         if i % 9 == 0:
  27.             print(i,end=" ")
  28.         if i % 15 == 0:
  29.             print(i,end=" ")
  30.         listi2.append(i)
  31.         return listi2
  32.  
  33. def fra_til(talnalisti,fra,til):
  34.     talnalisti = []
  35.     for i in range(fra,til):
  36.         talnalisti.append(i)
  37.     return talnalisti
  38.  
  39. class Klasi_1:
  40.     def __init__(self,tala1,tala2,tala3):
  41.         self.tala1 = tala1
  42.         self.tala2 = tala2
  43.         self.tala3 = tala3
  44.  
  45.     def reikningur(self):
  46.         utreikningur = ((tala1+tala2+tala3)/2)
  47.         return print("%.3f"%utreikningur)
  48.  
  49. class Klasi_2:
  50.     def __init__(self,fj_gira ,teg_hjol=""):
  51.         self.tegund_hjol = teg_hjol
  52.         self.fjoldi_gira = fj_gira
  53.  
  54.     def stening(self):
  55.         return print("   Hjólið mitt er  {} og er með {} gíra.".format(self.tegund_hjol,self.fjoldi_gira))
  56.  
  57.  
  58. print("-------------------verkefni 1-------------------")
  59. listiA = bua_til_lista(200,300)
  60. print("sýna lista 1 ")
  61. syna_lista(listiA)
  62. print("\n")
  63. print("meðaltal lista 1: ")
  64. medaltal(listiA)
  65. print("\n")
  66. listiB = bua_til_lista(50,75,25)
  67. print("\n")
  68. print("sýna listaB")
  69. syna_lista(listiB)
  70. print("\n")
  71. print("tölur i listaB. deilanlegar með 9 og 15")
  72. print("Mögulegar töur sem birtast eru:54, 60, 63, 72 og 75")
  73. print(deilanlegt_med_9_og_15(listiB))
  74. print("\n")
  75. print("tala frá og til með")
  76. print(fra_til(listiB,55,70))
  77. print("\n")
  78. print("-------------------verkefni 2-------------------")
  79. klasi1 = Klasi_1
  80.  
  81. tala1 = int(input("veldu heiltölu: "))
  82. tala2 = int(input("veldu heiltölu: "))
  83. tala3 = int(input("veldu heiltölu: "))
  84. tolur = Klasi_1(tala1,tala2,tala3)
  85.  
  86. klasi1.reikningur(tolur)
  87.  
  88. tegund = input("hverskonar tegund af hjóli ert þú með?: ")
  89. fjoldi_gira = int(input("hveru marga gíra er það hjól með?: "))
  90.  
  91. hjol = Klasi_2(fjoldi_gira,tegund)
  92.  
  93. Klasi_2.stening(hjol)
  94.  
  95. fra_til(listiB,55,300)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top