Advertisement
Guest User

Untitled

a guest
Oct 13th, 2015
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.76 KB | None | 0 0
  1. a = [1, 2, 3, 4, 5, 6, 7, 8, 9]
  2.  
  3.  
  4. def counting():
  5. counter = 0
  6. while counter < 10:
  7. print("Hello")
  8. counter += 1
  9. else:
  10. print("Bye!")
  11. inp = input('If you would like to repeat, press (y) otherwise press (n)')
  12. while True:
  13. if inp.lower() == 'y':
  14. counting()
  15. break
  16. elif inp.lower() == 'n':
  17. menu()
  18. break
  19. elif inp != str:
  20. print('not recognised')
  21. inp = input('If you would like to repeat, press (y) otherwise press (n)')
  22.  
  23.  
  24.  
  25. def count2():
  26. li = ['Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello', 'Hello']
  27. for x in li:
  28. print (x)
  29. inp = input('If you would like to repeat, press (y) otherwise press (n)')
  30. while True:
  31. if inp.lower() == 'y':
  32. count2()
  33. break
  34. elif inp.lower() == 'n':
  35. menu()
  36. break
  37. elif inp != str:
  38. print('not recognised')
  39. inp = input('If you would like to repeat, press (y) otherwise press (n)')
  40.  
  41.  
  42. def even():
  43. for x in range(10, 20):
  44. even_ = []
  45. odd_ = []
  46. if x % 2 == 0:
  47. even_.append(x)
  48. else:
  49. odd_.append(x)
  50. return even_
  51. inp = input('If you would like to repeat, press (y) otherwise press (n)')
  52. while True:
  53. if inp.lower() == 'y':
  54. even()
  55. break
  56. elif inp.lower() == 'n':
  57. menu()
  58. break
  59. elif inp != str:
  60. print('not recognised')
  61. inp = input('If you would like to repeat, press (y) otherwise press (n)')
  62.  
  63.  
  64. def prime():
  65. print('')
  66. print('This is a function to give you all the pri'
  67. 'e numbers between two numbers you enter')
  68. print('Type in two numbers and you will get all the prime numbers between the two')
  69. print('')
  70. while True:
  71. try:
  72. x = int(input('Enter a number: '))
  73. y = int(input('Enter a last num: '))
  74. for z in range(x, y):
  75. p = []
  76. for n in range(1, z+1):
  77. if z % n == 0:
  78. p.append(n)
  79. if len(p) == 2:
  80. print(z)
  81. break
  82. except ValueError:
  83. print('Please enter a number')
  84. while True:
  85. inp = input('If you would like to repeat, press (y) otherwise press (n)')
  86. if inp.lower() == 'y':
  87. prime()
  88. break
  89. elif inp.lower() == 'n':
  90. menu()
  91. break
  92. elif inp != str:
  93. print('not recognised')
  94. inp = input('If you would like to repeat, press (y) otherwise press (n)')
  95.  
  96.  
  97. def pythag():
  98. while True:
  99. try:
  100. first = int(input('Enter a number: '))
  101. second = int(input('Enter another number: '))
  102. while True:
  103. if first != abs(first) or second != abs(second):
  104. print('Triangle sides cannot be negative')
  105. first = int(input('Enter a number: '))
  106. second = int(input('Enter another number: '))
  107. else:
  108. break
  109. c = first ** 2
  110. d = second ** 2
  111. e = c + d
  112. f = e ** 0.5
  113. print('The Pythagoras theorem calculation of your numbers is: ', f)
  114. break
  115. except ValueError:
  116. print('That s not a number, try again')
  117. while True:
  118. inp = input('If you would like to repeat, press (y) otherwise press (n)')
  119. if inp.lower() == 'y':
  120. pythag()
  121. break
  122. elif inp.lower() == 'n':
  123. menu()
  124. break
  125. elif inp != str:
  126. print('not recognised')
  127. inp = input('If you would like to repeat, press (y) otherwise press (n)')
  128.  
  129.  
  130.  
  131. def menu():
  132. print('')
  133. print('A: Hello Counter')
  134. print('')
  135. print('B: Counter 2')
  136. print('')
  137. print('C: Find even numbers')
  138. print('')
  139. print('D: Prime Number')
  140. print('')
  141. print('E: Pythagoras Theorem')
  142. print('')
  143. ans = input('Choose a Function: ')
  144. while True:
  145. if ans.lower() == 'a':
  146. counting()
  147. break
  148. elif ans.lower() == 'b':
  149. count2()
  150. break
  151. elif ans.lower() == 'c':
  152. even()
  153. break
  154. elif ans.lower() == 'd':
  155. prime()
  156. break
  157. elif ans.lower() == 'e':
  158. pythag()
  159. else:
  160. print('Function not recognised. Please try again')
  161. ans = input('Choose a function: ')
  162.  
  163. menu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement