Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I asume this is for the school, so this maybe can help you.</p> <pre><code> #!/usr/bin/env python import re #put the logic in an object like enviroment class CalculatorProto(object): def __init__(self, numberone, numbertwo): """ initialize the data """ self.firsn = numberone self.twon = numbertwo def Verifynumber(self): """ verify is you pass abs numbers """ numbers = re.compile("^[0-9]+$") if numbers.search(self.firsn) and numbers.search(self.twon): self.firsn = int(self.firsn) self.twon = int(self.twon) return True else: return False def sum(self): """ manage sum """ rsum = self.firsn + self.twon return rsum def rest(self): """ manage rest """ if self.firsn &gt; self.twon: rrest = self.firsn - self.twon return rrest else: rrest = self.twon - self.firsn return rrest def div(self): """ manage div """ if int(self.firsn) &gt; int(self.twon): if self.twon != 0: rdiv = self.firsn / self.twon return rdiv return "Is not good idea div a number by 0" else: if self.firsn != 0: rdiv = self.twon / self.firsn return rdiv return "Is not good idea div a number by 0" def mul(self): rmul = self.firsn * self.twon return rmul if __name__ == "__main__": #here you cant write you small interface print "Enter two numbers, and a operation please" o = raw_input("One: ") t = raw_input("Two: ") operation = raw_input("Operation: ") while operation not in ("sum", "div", "rest", "mul"): print "WTF?? Enter a valid operation" print "sum\ndiv\nrest\nor mul" operation = raw_input("Operation: ") cal = CalculatorProto(o, t) if cal.Verifynumber(): exec("print cal.%s()" % operation) else: print "Please insert absolute numbers" </code></pre> <p>You cant modify this, for a more complex manage.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload