Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env python3
- #-*- coding: utf-8 -*-
- """ This is a test script.
- """
- # ################# class definition ######################################
- class ringBuf:
- def __init__(self, items):
- self.maxItems = items
- self.items = 0
- self.newItems = 0
- self.ringData = [0 for i in range (items)]
- self.readP = 0
- self.writeP = 0
- def readItem(self):
- if self.newItems == 0:
- raise StopIteration
- else:
- thisItem = self.ringData[self.readP]
- self.newItems -= 1
- self.readP = (self.readP + 1) % self.maxItems
- return thisItem
- def writeItem(self, item):
- self.ringData[self.writeP] = item
- self.writeP = (self.writeP + 1) % self.maxItems
- if self.newItems < self.maxItems:
- self.newItems += 1
- else:
- self.readP = (self.readP + 1) % self.maxItems
- if self.items < self.maxItems:
- self.items += 1
- def getList(self):
- thisList = [self.ringData[self.writeP]]
- thisList.clear()
- thisReadP = (self.maxItems + self.writeP - self.items) % self.maxItems
- for i in range(self.items):
- thisList.append(self.ringData[thisReadP])
- thisReadP = (thisReadP + 1) % self.maxItems
- return thisList
- def readPos(self):
- return self.readP
- def writePos(self):
- return self.writeP
- def itemCount(self):
- return self.items
- def maxItems(self):
- return self.maxItems
- def newItems(self):
- return self.newItems
- # ################# here comes the main code ##############################
- ringInst = ringBuf(7)
- while True:
- for i in range(3):
- print(str(i + 1) + ". Ganzzahl: ", end = "")
- number = int(input())
- ringInst.writeItem(number)
- print("Whole ring listed: ", str(ringInst.getList()))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement