Python program to demonstrate simple calculator.
print("=== Python Simple Calculator ===")
print("1. Addition")
print("2. Subtraction")
print("3. Multiplication")
print("4. Division")
choice = input("\nEnter your choice: \n")
num1 = int(input("Enter number 1: "))
num2 = int(input("Enter number 2: "))
print("\nAnswer for Given Inputs:")
if choice == '1':
print(num1, "+", num2, "=", num1 + num2)
elif choice == '2':
print(num1, "-", num2, "=", num1 - num2)
elif choice == '3':
print(num1, "*", num2,"=", num1*num2)
elif choice == '4':
print(num1, "/", num2, "=", num1/num2)
else:
print("Invalid input.")
Output of program
=== Python Simple Calculator ===
1. Addition
2. Subtraction
3. Multiplication
4. Division
Enter your choice:
1
Enter number 1: 5
Enter number 2: 6
Answer for Given Inputs:
5 + 6 = 11
Popular Python String Methods ( Functions )
Method Description
- count() It returns the number of times a specified value occurs in a string
- capitalize() It converts the first character of a string into upper case
- casefold() Converts string into lower case
- endswith() Returns true if the string ends with the specified value
- find() Searches the string for a specified value and returns the position of where it was found
- index() Searches the string for a specified value and returns the position of where it was found
- isdigit() Returns True if all characters in the string are digits
- islower() Returns True if all characters in the string are lower case
- isalnum() Returns True if all characters in the string are alphanumeric
- isalpha() Returns True if all characters in the string are in the alphabet
- isdecimal() Returns True if all characters in the string are decimals
- isspace() Returns True if all characters in the string are whitespaces
- istitle() Returns True if the string follows the rules of a title
- isupper() Returns True if all characters in the string are upper case
- join() Joins the elements of an iterable to the end of the string
- ljust() Returns a left justified version of the string
- lower() Converts a string into lower case
- upper() Converts a string into upper case
- lstrip() Returns a left trim version of the string
- replace() Returns a string where a specified value is replaced with a specified value
- rsplit() Splits the string at the specified separator, and returns a list
- rstrip() Returns a right trim version of the string
- startswith() Returns true if the string starts with the specified value
- swapcase() Swaps cases, lower case becomes upper case and vice versa
- title() Converts the first character of each word to upper case
- strip() Returns a trimmed version of the string