def MenuGeneral(): print ("""************ Calculadora Basica ****************** Opciones de la Calculadora 1) Suma 2) Resta 3) Multiplicacion 4) Division 5) Salir""") def Calculadora(): """Funcion Para Calcular Operaciones Aritmeticas""" MenuGeneral() opc=int(input("Selecione Opcion ")) while (opc >0 and opc <5): x = int(input("Ingrese Numero\n")) y = int(input("Ingrese Otro Numero\n")) if (opc==1): print ("La Suma es:",x+y) elif(opc==2): print ("La Resta es:"+x-y) elif(opc==3): print ("La Multiplicacion es:"+x*y) elif(opc==4): try: print ("La Division es:%.2f" %(float(x)/float(y))) except ZeroDivisionError: print ("No se Permite la Division Entre 0") if (opc!=5): MenuGeneral() opc = int(input("Selecione Opcion\n")) Calculadora() print ("Final del programa")
def MenuGeneral(): print ("""************ Calculadora Basica ****************** Opciones de la Calculadora 1) Suma 2) Resta 3) Multiplicacion 4) Division 5) Salir""") def Calculadora(): """Funcion Para Calcular Operaciones Aritmeticas""" MenuGeneral() opc=int(input("Selecione Opcion ")) while (opc >0 and opc <5): x = int(input("Ingrese Numero\n")) y = int(input("Ingrese Otro Numero\n")) if (opc==1): print ("La Suma es:",x+y) elif(opc==2): print ("La Resta es:"+x-y) elif(opc==3): print ("La Multiplicacion es:"+x*y) elif(opc==4): try: print ("La Division es:%.2f" %(float(x)/float(y))) except ZeroDivisionError: print ("No se Permite la Division Entre 0") if (opc!=5): MenuGeneral() opc = int(input("Selecione Opcion\n")) Calculadora() print ("Final del programa")
class mathStack: def __init__(self): self.items = [] def isEmpty(self): return self.items == [] def push(self,item): self.items.append(item) def pop(self): return self.items.pop() def peek(self): return self.items[len(self.items)-1] def size(self): return len(self.items) class mathObject: def __init__(self): self.number = None self.operation = None def isNumber(self): return self.number is type(int) def isOperation(self): return self.operation is type(str) def setNumber(self, item): self.number = item def setOperation(self,item): self.operation = item def setMathObject(self,item): if item is type(int): setNumber(item) elif item is type(str): setOperation(item) class mathEngine: def __init__(self): self.mathObjs = [] self.mStack = mathStack() self.expression = None def setExpression(self,exp): self.expression = exp def getExpression(self): return self.expression def splitExpression(self): tokens = self.expression.split(" ") for index in range(len(tokens)): x = mathObject() x.setMathObject(tokens) self.mathObjs = x x = mathEngine() x.setExpression(input()) print(x.getExpression()) x.splitExpression()
from Tkinter import * root = Tk() frame = Frame(root) frame.pack() bottomframe = Frame(root) bottomframe.pack( side = BOTTOM ) redbutton = Button(frame, text="Red", fg="red") redbutton.pack( side = LEFT) greenbutton = Button(frame, text="Brown", fg="brown") greenbutton.pack( side = LEFT ) bluebutton = Button(frame, text="Blue", fg="blue") bluebutton.pack( side = LEFT ) blackbutton = Button(bottomframe, text="Black", fg="black") blackbutton.pack( side = BOTTOM) root.mainloop()
import math as m float first_variable, second_variable def differencial_of_constant(first_variable): first_variable = float(input()) print("0") def differencial_of_x(first_variable): y = first_variable print("dy = dx") def differencial_of_pow_x(first_variable, second_variable): second_variable = float(input()) y = first_variable ** second_variable print("dy = ", second_variable * first_variable ** (second_variable - 1),"dx") def differencial_of_pow_a_x(first_variable, second_variable): second_variable = float(input()) y = second_variable ** first_variable print("dy = ", second_variable ** first_variable * m.log(second_variable, [m.e]), "dx") def differencial_of_log_x(first_variable, second_variable): second_variable = int(input()) if first_variable >= 0: y = m.log(first_variable, [second_variable]) print("dy = ", 1 / (first_variable * m.log(second_variable, [m.e])), "dx") else: print("Error") def differencial_of_sin(first_variable): y = m.sin(first_variable) print("dy = ", m.cos(first_variable), "dx") def differencial_of_cos(first_variable): y = m.cos(first_variable) print("dy = -", m.sin(first_variable)) def differencial_of_tan(first_variable): if m.cos(first_variable) != 0: y = m.tan(first_variable) print("dy = ", 1 / m.cos(first_variable) ** 2, "dx") else: print("Error") def differencial_of_cot(first_variable): if m.sin(first_variable) != 0: y = 1 / m.tan(first_variable) print("dy = -", 1 / m.sin(first_variable)) else: print("Error") def differencial_of_arcsin(first_variable): if first_variable in range(-m.pi / 2, m.pi / 2) and m.abs(first_variable) <= 1: print("dy = ", 1 / (m.sqrt(1 - first_variable ** 2)), "dx") else: print("Error") def differencial_of_arccos(first_variable): if first_variable in range(-m.pi / 2, m.pi / 2) and m.abs(first_variable) <= 1: print("dy = -", 1 / m.sqrt((1 - first_variable ** 2)), "dx") else: print("Error") def differencial_of_arctan(first_variable): print("dy = ", 1 / (1 + first_variable ** 2), "dx") def differencial_of_arccot(first_variable): print("dy = - ", 1 / (1 + first_variable ** 2), "dx")
while True: print("Welcome To Ahmed's Simple Two Number Calculator") print("Please Choose What You Want To Do:") print("Enter 'add' For Addition") print("Enter 'subtract' For Subtraction") print("Enter 'divide' For Division") print("Enter 'multiply' For Multiplication") print("Enter 'quit' To Quit The Calculator") print("Please Enter Your Choice Exactly As Written In The Instructions !") print() break while True: choice=input() if choice=="quit": break elif choice=="add": num1 = float(input("Enter A Number")) num2 = float(input("Enter Another Number")) result = str(num1+num2) print() print("The Answer Is = "+result) print() elif choice=="subtract": num1 = float(input("Enter A Number")) num2 = float(input("Enter Another Number")) result = str(num1-num2) print() print("The Answer Is = "+result) print() elif choice=="multiply": num1 = float(input("Enter A Number")) num2 = float(input("Enter Another Number")) result = str(num1*num2) print() print("The Answer Is = "+result) print() elif choice=="divide": num1 = float(input("Enter A Number")) num2 = float(input("Enter Another Number")) result = str(num1/num2) print() print("The Answer Is = "+result) print() else: print("!! UNKOWN CHOICE !!\nPLEASE ENTER A VALID CHOICE") continue
example of template class mylist=('foo','bar','ball','scoop','red') class template: def __init__(self,input1): self.input1=input1 def print1(self): for item in self.input1: if item.startswith('b'): print (item) elif item.startswith('f'): print(item+'..sorry') else: print(item+' - not for use') t1=template(mylist) t1.print1()
from functools import reduce def my_function(a): return a**2 def using_maps_or_not(): numbers = [1, 2, 3, 4] result = list(map(my_function, numbers)) """ this alternative is better than the built in function map because it is faster """ result2 = [n**2 for n in numbers] print(result) print(result2) def another_func(a): # even numbers return True return a % 2 == 0 """ using filter takes value and return boolean """ def using_filter(): numbers = [1, 2, 3, 4] result = list(filter(another_func, numbers)) print(result) result = list(filter(lambda a: a % 2 == 0, numbers)) print(result) result = [n for n in numbers if n % 2 == 0] print(result) """ if an else statement is needed, place the selection before the for statement """ result = [n if n % 2 == 0 else n +1 for n in numbers ] print(result) """ using reduce needs to import functools! """ def f(a, b): return a if a < b else b def main(): numbers = [1, 2, 3, 4] result = reduce(f, numbers) print(result) if __name__ == '__main__': main()
from math import sqrt, floor def sito(dane): # dla każdej liczby z pomiędzy 2 do sqrt(y) for i in range(2, floor(sqrt(dane[-1]))): # oraz dla każdej wielokrotności i for j in range(i*i, dane[-1] + 1, i): # jeżeli dana wielokrotność znajduje się na liście (dane) to ją usuwam if j in dane: dane.remove(j) return dane def nwd(x,y): # Zwracamy którąkolwiek z liczb jeżeli są równe if x == y: return x # zamieniamy miejscami x i y jeżeli x jest większe od y if x > y: x, y = y, x # dopóki x jest różne od zera: # przypisujemy do x wynik dzielenia modulo y mod x # a do y przypisujemy poprzedną wartość x while x != 0: x, y = y % x, x return abs(y) dane = list(range(41, 1019)) print(sito(dane))
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more