Facebook
From Melisa-Rebeca, 2 Weeks ago, written in Python.
Embed
Download Paste or View Raw
Hits: 176
  1. #1
  2. #a)
  3. def Unknown(x, y):
  4.     if x < y:
  5.         print(str(x+y))
  6.         return input((Unknown(x+1, y) * 2))
  7.     elif x == y:
  8.         return 1
  9.     else:
  10.         print(str(x+y))
  11.         return int((Unknown(x-1,y)/2))
  12.     #b
  13. print('10 and 15')
  14. print(str(Unknown(10,15)))
  15.  
  16. print('10 and 10')
  17. print(str(Unknown(10,10)))
  18.  
  19. print('15 and 10')
  20. print(str(Unknown(15,10)))
  21. #ii)
  22. #won't print right
  23.  
  24. #c
  25. def IterativeUnknown(x,y):
  26.     #base case
  27.     Total = 1
  28.     while x != y:
  29.         print(str(x+y))
  30.         if x < y:
  31.             x = x + 1
  32.             Total = Total * 2
  33.         else:
  34.             x = x - 1
  35.             Total = Total / 2
  36.     return
  37. print('10 and 15')
  38. print(str(IterativeUnknown(10,15)))
  39.  
  40. print('10 and 10')
  41. print(str(IterativeUnknown(10,10)))
  42.  
  43. print('15 and 10')
  44. print(str(IterativeUnknown(15,10)))
  45. #d screenshot result
  46.  
  47.  
  48. #2
  49. #a
  50. class Picture():
  51.     def __init__(self, DescriptionP, WidthSizeP, HeightSizeP, FrameColourP):
  52.          self.__Descripti
  53.         self.__WidthSize = WidthSizeP
  54.         self.__HeightSize = HeightSizeP
  55.         self.__FrameColour = FrameColourP
  56. #b
  57.     def GetDescription(self):
  58.         return self.__Description
  59.     def GetHeight(self):
  60.         return self.__HeightSize
  61.     def GetWidth(self):
  62.         return self.__WidthSize
  63.     def GetColour(self):
  64.         return self.__FrameColour
  65. #c
  66.     def SetDescription(self, description):
  67.          self.__Descripti
  68. #d
  69. Array = [None] * 100 #TYPE Picture
  70.  
  71. #e
  72.     def ReadData(Array):
  73.         Count = 0
  74.         try:
  75.             file = open('Pictures.txt', 'r')
  76.              Descripti
  77.             while Description != '':
  78.                 Width = int(file.readline().strip())
  79.                 Height = int(file.readline().strip())
  80.                 Frame = int(file.readline().strip())
  81.                 myObject = Picture(Description,Width,Height,Frame) #here
  82.                 Count  Count + 1
  83.             file.close()
  84.         except IOError:
  85.             print('File not found')
  86.         return Count
  87. #f
  88. #call the function ReadData()
  89. ReadData(Array) #here
  90.  
  91. #g
  92. UserEnteredColour = input('Enter your color requirements for the picture')
  93. UserEnteredMaxWidth = input('Enter your maximum width requirements for the picture')
  94. UserEnteredMaxHeight = input('Enter your maximum height requirements for the picture')
  95. for element in Array:
  96.     if UserEnteredColour == element.GetColour() and UserEnteredMaxWidth == element.GetWidth() and UserEnteredMaxHeight == element.GetHeight(): #the getters r not self completing here when using element
  97.         print(UserEnteredColour)
  98.         print(UserEnteredMaxWidth)
  99.         print(UserEnteredMaxHeight