CALCULATOR
- Get link
- X
- Other Apps
CALCULATOR
This post shows a simple calculator using python(2.7).It uses function for doing operations.
an example:for addition - def addition(x,y):
"This Function For Addition"
return x+y.
This function reads 2 values from the main and returns the sum to 'c'..
def addition(x,y):
"This Function For Addition"
return x+y
def substraction(x,y):
"This Function For Substraction"
return(x-y)
def multiplication(x,y):
"This Function For Multiplication"
return(x*y)
def division(x,y):
"This Function For Division"
return(x/y)
print "Select A Operation"
print "1-> Addition"
print "2-> Substraction"
print "3-> Multiplication"
print "4-> Division"
choice=int(input("Enter A Choice(1,2,3,4):"))
#Main Program
if choice>4:
print "Sorry..... Please Enter A Valid Input (1,2,3,4)"
else:
a=float(input("Enter 1st number:"))
b=float(input("Enter 2nd number:"))
if choice==1:
c=addition(a,b)
print a,"+",b,"Is=",c
elif choice==2:
d=substraction(a,b)
print a,"-",b,"is =",d
elif choice==3:
e=multiplication(a,b)
print a,"*",b,"is =",e
elif choice==4:
f=division(a,b)
print a,"/",b,"is =",f
OUTPUT
- Get link
- X
- Other Apps
Popular posts from this blog
FIND NUMBER OF VOWELS IN A STRING
FIND NUMBER OF VOWELS IN A STRING c=raw_input("Enter A String:") b=c.lower() x=0 for letter in b: if letter in "aeiou": x+=1 print "Total Number Of Vowels = " + str(x) print "Number Of Vowels In Each" d,e,f,g,h=0,0,0,0,0 for letter in b: if letter in "a": d+=1 print "a=" +str(d) for letter in b: if letter in "e": e+=1 print "e=" +str(e) for letter in b: if letter in "i": f+=1 print "i=" +str(f) for letter in b: if letter in "o": g+=1 print "o=" +str(g) for letter in b: if letter in "u": h+=1 print "u=" +str(h) OUTPUT
TO FIND EVEN NUMBERS UP TO N
INTRODUCTION TO PYTHON
INTRODUCTION TO PYTHON Welcome! Python is a widely used high-level programming language for general-purpose programming, created by Guido van Rossum and first released in 1991. An interpreted language, Python has a design philosophy that emphasizes code readability (notably using whitespace indentation to delimit code blocks rather than curly brackets or keywords), and a syntax that allows programmers to express concepts in fewer lines of code than might be used in languages such as C++ or Java. The language provides constructs intended to enable writing clear programs on both a small and large scale. Python features a dynamic type system and automatic memory management and supports multiple programming paradigms, including object-oriented, imperative, functional programming, and procedural styles. It has a large and comprehensive standard library.[26] Python interpreters are available for many operating systems, allowing P...