Guest User

Untitled

a guest
May 5th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.77 KB | None | 0 0
  1. from numbers import *
  2. from strings import *
  3.  
  4. def print_instructions():
  5. print("Welcome")
  6. print("0 - Print instructions")
  7. print("1 - Choose a number function")
  8. print("2 - Choose a string function")
  9. print("3 - Exit the program")
  10.  
  11.  
  12. def print_number_instructions():
  13. print("These are instructions for the number functions")
  14. print("0 - Print Instructions")
  15. print("1 - Find Gamma using law of cosines")
  16. print("2 - Find length of side c using law of cosines")
  17. print("3 - Find nth fibonacci number")
  18. print("4 - Check is number is even")
  19. print("5 - Use Pythagorean theorem to find hypotenuse")
  20.  
  21.  
  22. def number_handler():
  23. print_number_instructions()
  24. choice = int(input("Choose an option: "))
  25. if choice == 0:
  26. print_number_instructions()
  27. elif choice == 1:
  28. a = float(input("Enter a: "))
  29. b = float(input("Enter b: "))
  30. c = float(input("Enter c: "))
  31. print("Gamma: " + str(law_of_cosines_gamma(a, b, c)))
  32. elif choice == 2:
  33. a = float(input("Enter a: "))
  34. b = float(input("Enter b: "))
  35. gamma = float(input("Enter gamma: "))
  36. print("Gamma: " + str(law_of_cosines_normal(a, b, gamma)))
  37. elif choice == 3:
  38. n = int(input("Enter n: "))
  39. print("nth fibonacci number: " + str(fib(n)))
  40. elif choice == 4:
  41. e = int(input("Enter your number: "))
  42. print("Answer: " + str(is_even(e)))
  43. elif choice == 5:
  44. a = float(input("Enter a: "))
  45. b = float(input("Enter b: "))
  46. print("Answer: " + str(pythagorean_theorem(a, b)))
  47. else:
  48. print("Not a valid choice")
  49.  
  50.  
  51. def print_string_instructions():
  52. print("0 - Print Instructions")
  53. print("1 - Encrypt a string")
  54. print("2 - Decrypt a string")
  55. print("3 - Check if string is a palindrome")
  56. print("4 - Reverse a string")
  57.  
  58.  
  59. def string_handler():
  60. print_string_instructions()
  61. choice = int(input("Enter your choice: "))
  62. default_cipher = "qwertyuiopasdfghjklzxcvbnm QWERTYUIOPASDFGHJKLZXCVBNM0987654321"
  63. if choice == 0:
  64. print_string_instructions()
  65. elif choice == 1:
  66. str_to_encrypt = input("Enter your string: ")
  67. print("Enter 1 to use default cipher.")
  68. cipher = input("Enter your cipher: ")
  69. if cipher == "1":
  70. print("Encrypted string: " + encrypt(str_to_encrypt, default_cipher))
  71. else:
  72. print("Encrypted string: " + encrypt(str_to_encrypt, cipher))
  73. elif choice == 2:
  74. str_to_decrypt = input("Enter your string: ")
  75. print("Enter 1 to use default cipher.")
  76. cipher = input("Enter your cipher: ")
  77. if cipher == "1":
  78. print("Decrypted string: " + decrypt(str_to_decrypt, default_cipher))
  79. else:
  80. print("Decrypted string: " + decrypt(str_to_decrypt, cipher))
  81. elif choice == 3:
  82. str_to_check = input("Enter your string: ")
  83. print("Answer: " + check_palindrome(str_to_check))
  84. elif choice == 4:
  85. str_to_reverse = input("Enter string: ")
  86. print("Reversed string: "+ reverse(str_to_reverse))
  87. else:
  88. print("Not a valid choice")
  89.  
  90.  
  91. quit_ = False
  92.  
  93. while not quit_:
  94. choice = int(input("Choose an option: "))
  95. if choice == 0:
  96. print_instructions()
  97. elif choice == 1:
  98. number_handler()
  99. elif choice == 2:
  100. string_handler()
  101. else:
  102. print("Bye")
  103. quit(0)
  104. #
  105. # # Tests
  106. # # Lists
  107. # l = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  108. # print("List " + str(l))
  109. # print("Sum of l: " + str(addList(l)))
  110. # print("All elements in l sqared: " + str(squareList(l)))
  111. # lSort = list(list(numpy.random.randint(low=0, high=10, size=(1, 10)))[0])
  112. # print("Random list to sort: " + str(lSort))
  113. # print("Sorted: " + str(sort(lSort)))
  114. # print("-----")
  115. # # Numbers
  116. # print("5 is prime: " + str(is_prime(5)))
  117. # print("10 is prime: " + str(is_prime(10)))
  118. # print("5 is even: " + str(is_even(5)))
  119. # print("10 is even: " + str(is_even(10)))
  120. # print("5 is odd: " + str(is_odd(5)))
  121. # print("10 is odd: " + str(is_odd(10)))
  122. # print("10 - 5 = " + str(subtract(10, 5)))
  123. # print("10 * 5 = " + str(multipliy(10, 5)))
  124. # print("10 / 5 = " + str(divide(10, 5)))
  125. # print("Circle of Numbers for n = 10 and firstNumber = 2: " + str(circle_of_numbers(10, 2)))
  126. # print("Perimeter of rectangle with side length 10 and 8: " + str(perimeter_of_rectangle(10, 8)))
  127. # print("Area of rectangle with side length 10 and 8: " + str(area_of_rectangle(10, 8)))
  128. # print("Area of circle with radius 5: " + str(area_of_circle(radius=5)))
  129. # print("Area of circle with diameter 20: " + str(area_of_circle(diameter=20)))
  130. # print("Area of square with side 10: " + str(area_of_square(10)))
  131. # print("Perimeter of square with side 10: " + str(perimeter_of_square(10)))
  132. # print("Circumference of circle with radius 5: " + str(circumference(radius=5)))
  133. # print("Circumference of circle with diameter 7: " + str(circumference(diameter=7)))
  134. # print("Hypotenuse for right triangle legs 3 and 4: " + str(pythagorean_theorem(3, 4)))
  135. # print("Law of cosines for a, b = 10 and C = 25: " + str(law_of_cosines_normal(10, 10, 25)))
  136. # print("Calculating C with law of cosines when a = 5, b = 4, and c = 6: " + str(law_of_cosines_gamma(5, 4, 6)))
  137. # # print("423th fibonacci number: " + str(fib(423)))
  138. # print("-----")
  139. # print("String tests")
  140. # print("Check if 'civic' is a palindrome: " + str(check_palindrome("civic")))
  141. # print("Check if 'hello' is a palindrome: " + str(check_palindrome("hello")))
  142. # print("'Hello world' reversed: " + reverse("Hello world"))
  143. # print("Most common character in string 'Hello World': " + find_most_common_character("Hello World"))
  144. # cipher = "qwertyuiopasdfghjklzxcvbnm QWERTYUIOPASDFGHJKLZXCVBNM0987654321"
  145. # print("Encrypt 'Hello world 45' with cipher '" + cipher + "': " + encrypt("Hello world 45", cipher))
  146. # print("Decrypt 'Itssg vgksr 76' with cipher '" + cipher + "': " + decrypt("Itssg vgksr 76", cipher))
Add Comment
Please, Sign In to add comment