0% found this document useful (0 votes)
3 views

Basics of Python

The document outlines a simple Python calculator program that allows users to perform basic arithmetic operations such as addition, subtraction, multiplication, division, modulus, floor division, and exponentiation. It includes a menu for operation selection and prompts for user input to execute the chosen operation. The program continues to run until the user decides to exit.

Uploaded by

notsureabout99
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Basics of Python

The document outlines a simple Python calculator program that allows users to perform basic arithmetic operations such as addition, subtraction, multiplication, division, modulus, floor division, and exponentiation. It includes a menu for operation selection and prompts for user input to execute the chosen operation. The program continues to run until the user decides to exit.

Uploaded by

notsureabout99
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

07/10/2024, 13:34 Basics of Python

In [10]: def menu():


print ("##################")
print ("### CALCULATOR ###")
print ("##################")
print ("1. ADD")
print ("2. SUBTRACT")
print ("3. MULTIPLY")
print ("4. DIVIDE")
print ("5. MODULUS")
print ("6. FLOOR DIVISION")
print ("7. EXPONENT")
print ("0. EXIT")
print ()
ch = int(input("Enter your choice of operation : "))
return ch

In [13]: def operation():


x = menu()
if x == 0:
print ("Thank you for using our program...")
exit(0)
elif x == 1:
a = int(input("Enter the first value : "))
b = int(input("Enter the second value : "))
print ("The sum of {} and {} is {}".format(a, b, a + b))
elif x == 2:
a = int(input("Enter the first value : "))
b = int(input("Enter the second value : "))
print ("The difference between {} and {} is {}".format(a, b, a -
elif x == 3:
a = int(input("Enter the first value : "))
b = int(input("Enter the second value : "))
print ("The product of {} and {} is {}".format(a, b, a * b))
elif x == 4:
a = int(input("Enter the first value : "))
b = int(input("Enter the second value : "))
print ("The quotient of {} and {} is {}".format(a, b, a / b))
elif x == 5:
a = int(input("Enter the first value : "))
b = int(input("Enter the second value : "))
print ("The remainder of {} and {} is {}".format(a, b, a % b))
elif x == 6:
a = int(input("Enter the first value : "))
b = int(input("Enter the second value : "))
print ("The floor quotient of {} and {} is {}".format(a, b, a //
elif x == 7:
a = int(input("Enter the first value : "))
b = int(input("Enter the second value : "))
print ("The exponent of {} to the power {} is {}".format(a, b, a
else:
print("Sorry!! Wrong option entered...")

In [12]: while True:


operation()
rep = input("Do you want to try again... (Y/N) : ")
if rep in "Nn":
break

file:///home/pmskvb/Downloads/Basics of Python (1).html 1/2


07/10/2024, 13:34 Basics of Python

##################
### CALCULATOR ###
##################
1. ADD
2. SUBTRACT
3. MULTIPLY
4. DIVIDE
5. MODULUS
6. FLOOR DIVISION
7. EXPONENT
0. EXIT

The sum of 100 and 200 is 300


##################
### CALCULATOR ###
##################
1. ADD
2. SUBTRACT
3. MULTIPLY
4. DIVIDE
5. MODULUS
6. FLOOR DIVISION
7. EXPONENT
0. EXIT

The quotient of 100 and 50 is 2.0


##################
### CALCULATOR ###
##################
1. ADD
2. SUBTRACT
3. MULTIPLY
4. DIVIDE
5. MODULUS
6. FLOOR DIVISION
7. EXPONENT
0. EXIT

The exponent of 2 to the power 3 is 8

In [ ]:

file:///home/pmskvb/Downloads/Basics of Python (1).html 2/2

You might also like