Monday 17 February 2020

Python program for Simple Calculator

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

Tuesday 4 February 2020

Python String Methods ( Functions )

Popular Python String Methods ( Functions )


        Method         Description
  1. count() It returns the number of times a specified value occurs in a string
  2. capitalize() It converts the first character of a string into upper case
  3. casefold()   Converts string into lower case
  4. endswith() Returns true if the string ends with the specified value
  5. find() Searches the string for a specified value and returns the position of where it was found
  6. index() Searches the string for a specified value and returns the position of where it was found
  7. isdigit()        Returns True if all characters in the string are digits
  8. islower()      Returns True if all characters in the string are lower case
  9. isalnum()     Returns True if all characters in the string are alphanumeric
  10. isalpha()      Returns True if all characters in the string are in the alphabet
  11. isdecimal() Returns True if all characters in the string are decimals
  12. isspace()      Returns True if all characters in the string are whitespaces
  13. istitle()        Returns True if the string follows the rules of a title
  14. isupper()      Returns True if all characters in the string are upper case
  15. join() Joins the elements of an iterable to the end of the string
  16. ljust() Returns a left justified version of the string
  17. lower() Converts a string into lower case
  18. upper() Converts a string into upper case
  19. lstrip()         Returns a left trim version of the string
  20. replace()      Returns a string where a specified value is replaced with a specified value
  21. rsplit()         Splits the string at the specified separator, and returns a list
  22. rstrip()         Returns a right trim version of the string
  23. startswith() Returns true if the string starts with the specified value
  24. swapcase() Swaps cases, lower case becomes upper case and vice versa
  25. title() Converts the first character of each word to upper case
  26. strip() Returns a trimmed version of the string