Guest User

Untitled

a guest
Jul 17th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.03 KB | None | 0 0
  1. from random import *
  2.  
  3. def greet():
  4. print("Hello, I'm chatbot. Ask me a question!")
  5.  
  6. def hangman():
  7.  
  8. wordChosen = input("Write a word for someone to guess. ")
  9.  
  10. list = []
  11. wrong = []
  12.  
  13. tries = 6
  14. end = 1
  15. for i in range(len(wordChosen)):
  16. list.append("_")
  17. print(list)
  18.  
  19. while(tries > 0):
  20. if(end == len(wordChosen)):
  21. break
  22. else:
  23. guess = input("choose a letter: ")
  24. if(guess in wordChosen):
  25. for i in range((len(wordChosen))):
  26. # if the letter at i = guess replace list num with guess
  27. if(guess == wordChosen[i]):
  28. list[i] = guess
  29. print(list)
  30. end = end + 1
  31. else:
  32. print("try again")
  33. wrong.append(guess)
  34. tries = tries - 1
  35. print("tries: ", tries)
  36.  
  37. if(tries == 0):
  38. print("game over")
  39. if(end == len(wordChosen) and tries > 0):
  40. print("you won!")
  41.  
  42. def default():
  43. print("That's cool!")
  44.  
  45. def guessNum():
  46. random = randint(1,100)
  47.  
  48. guess = input("Guess a number 1-100 inc ")
  49.  
  50. for i in range(10):
  51.  
  52. if not guess.isnumeric():
  53. print("thats not a pos num")
  54. guess = input("Guess a number 1-100 inc ")
  55.  
  56. else:
  57. guess = int(guess)
  58. if (guess > random):
  59. print("too high")
  60. guess = input("Guess a number 1-100 inc ")
  61.  
  62. elif(guess < random):
  63. print("too low")
  64. guess = input("Guess a number 1-100 inc ")
  65.  
  66. elif(guess == random):
  67. print("you got it!")
  68. break
  69. else:
  70. print("try again")
  71. guess = input("Guess a number 1-100 inc ")
  72.  
  73. def calc():
  74. num1 = input("What is your first number? ")
  75. num2 = input("What is you second number? ")
  76. num1 = int(num1)
  77. num2 = int(num2)
  78. math = 0
  79. mathfunc = input("What would you like to do? (multiply, add, subtract, divide) ")
  80. if(mathfunc == "add"):
  81. math = num1 + num2
  82. print(num1, " + ", num2, " = ", math)
  83. elif(mathfunc == "multiply"):
  84. math = num1 * num2
  85. print(num1, " * ", num2, " = ", math)
  86. elif(mathfunc == "divide"):
  87. math = num1 / num2
  88. print(num1, " / ", num2, " = ", math)
  89. elif(mathfunc == "subtract"):
  90. math = num1 - num2
  91. print(num1, " - ", num2, " = ", math)
  92. else:
  93. while (mathfunc != "add" and mathfunc != "subtract" and mathfunc != "multiply" and mathfunc != "divide"):
  94. print("That choice is not valid")
  95. mathfunc = input("What would you like to do? (multiply, add, subtract, divide) ")
  96. if(mathfunc == "add"):
  97. math = num1 + num2
  98. print(num1, " + ", num2, " = ", math)
  99. elif(mathfunc == "multiply"):
  100. math = num1 * num2
  101. print(num1, " * ", num2, " = ", math)
  102. elif(mathfunc == "divide"):
  103. math = num1 / num2
  104. print(num1, " / ", num2, " = ", math)
  105. elif(mathfunc == "subtract"):
  106. math = num1 - num2
  107. print(num1, " - ", num2, " = ", math)
  108.  
  109. def rps():
  110. #rockPaperScissors = ["rock", "paper", "scissors"] len(rockPaperScissors)
  111. rpsPlayer = input("What do you choose? (rock, paper, scissors) ")
  112. randomRPS = randint(0, 2)
  113. if(rpsPlayer == "rock" or rpsPlayer == "scissors" or rpsPlayer == "paper"):
  114. if(randomRPS == 0):
  115. if(rpsPlayer == "rock"):
  116. print("draw. My play: rock")
  117. elif(rpsPlayer == "scissors"):
  118. print("I win! My play: rock")
  119. elif(rpsPlayer == "paper"):
  120. print("You win! My play: rock")
  121. elif(randomRPS == 1):
  122. if(rpsPlayer == "paper"):
  123. print("draw. My play: paper")
  124. elif(rpsPlayer == "rock"):
  125. print("I win! My play: paper")
  126. elif(rpsPlayer == "scissors"):
  127. print("You win! My play: paper")
  128. elif(randomRPS == 2):
  129. if(rpsPlayer == "scissors"):
  130. print("draw. My play: scissors")
  131. elif(rpsPlayer == "paper"):
  132. print("I win! My play: scissors")
  133. elif(rpsPlayer == "rock"):
  134. print("You win! My play: scissors")
  135. else:
  136. while(rpsPlayer != "rock" and rpsPlayer != "scissors" and rpsPlayer != "paper"):
  137. print("That choice is not valid.")
  138. rpsPlayer = input("What do you choose? (rock, paper, scissors) ")
  139. if(randomRPS == 0):
  140. if(rpsPlayer == "rock"):
  141. print("draw. My play: rock")
  142. elif(rpsPlayer == "scissors"):
  143. print("I win! My play: rock")
  144. elif(rpsPlayer == "paper"):
  145. print("You win! My play: rock")
  146. elif(randomRPS == 1):
  147. if(rpsPlayer == "paper"):
  148. print("draw. My play: paper")
  149. elif(rpsPlayer == "rock"):
  150. print("I win! My play: paper")
  151. elif(rpsPlayer == "scissors"):
  152. print("You win! My play: paper")
  153. elif(randomRPS == 2):
  154. if(rpsPlayer == "scissors"):
  155. print("draw. My play: scissors")
  156. elif(rpsPlayer == "paper"):
  157. print("I win! My play: scissors")
  158. elif(rpsPlayer == "rock"):
  159. print("You win! My play: scissors")
  160.  
  161. def name():
  162. Letter1 = ["B", "S", "T", "L", "W"]
  163. Letter2 = ["a", "e", "i", "o", "u"]
  164. Letter3 = ["v", "n", "m", "r", "d"]
  165. Letter4 = ["a", "e", "i", "o", "u"]
  166. Letter5 = ["g", "h", "l", "f", "p"]
  167.  
  168. random1 = randint(0, (len(Letter1)-1))
  169. random2 = randint(0, (len(Letter2)-1))
  170. random3 = randint(0, (len(Letter3)-1))
  171. random4 = randint(0, (len(Letter4)-1))
  172. random5 = randint(0, (len(Letter5)-1))
  173.  
  174. word = Letter1[random1] + Letter2[random2] + Letter3[random3] + Letter4[random4] + Letter5[random5]
  175.  
  176. Letter6 = ["K", "G", "R", "Z", "M"]
  177. Letter7 = ["a", "e", "i", "o", "u"]
  178. Letter8 = ["y", "s", "t", "f", "g"]
  179. Letter9 = ["a", "e", "i", "o", "u"]
  180. Letter10 = ["d", "b", "j", "r", "z"]
  181. Letter11 = ["a", "e", "i", "o", "u"]
  182.  
  183. random6 = randint(0, (len(Letter6)-1))
  184. random7 = randint(0, (len(Letter7)-1))
  185. random8 = randint(0, (len(Letter8)-1))
  186. random9 = randint(0, (len(Letter9)-1))
  187. random10 = randint(0, (len(Letter10)-1))
  188. random11 = randint(0, (len(Letter11)-1))
  189.  
  190. word2 = Letter6[random6] + Letter7[random7] + Letter8[random8] + Letter9[random9]+ Letter10[random10] + Letter11[random11]
  191. full = word + " " + word2
  192. print(full)
  193.  
  194. def convo():
  195. jokes = ["What do you call a fish without eyes? Fsh. ", "What do you call an alligator detective? An investi-gator. ",
  196. "Why did the Clydesdale give the pony a glass of water?", "Why did the scarecrow win an award? Because he was outstanding in his field.",
  197. "There are two muffins baking in the oven. One muffin says to the other, “Phew, is it getting hot in here or is it just me?” The other muffin says, “AAAAHHH!! A TALKING MUFFIN!” ",
  198. "What lights up a soccer stadium? A soccer match.", "Why shouldn’t you write with a broken pencil? Because it’s pointless. ",
  199. "What’s the difference between the bird flu and the swine flu? One requires tweetment and the other an oinkment."]
  200. greeting = input("How are you doing today? I am doing good! ")
  201. if("good" in greeting or "great" in greeting):
  202. next = input("im happy you are well. Whats up? ")
  203. if("nothing" in next):
  204. print("Thats ok! I love doing nothing too")
  205. then = input("would you like to tell me a joke? ")
  206. if("yes" in then):
  207. print(jokes[randint(0, len(jokes))])
  208. return 0
  209. else:
  210. print("Thats ok. Bye!")
  211. return 0
  212. else:
  213. print("That sounds cool!")
  214. then = input("would you like to tell me a joke? ")
  215. if("yes" in then):
  216. print(jokes[randint(0, len(jokes))])
  217. return 0
  218. else:
  219. print("Thats ok. Bye!")
  220. return 0
  221. elif("bad" in greeting or "depressed" in greeting):
  222. next = input("I'm sorry you are not feeling well. Whats up? ")
  223. if("nothing" in next):
  224. print("Thats ok! I love doing nothing too")
  225. then = input("would you like to tell me a joke? ")
  226. if("yes" in then):
  227. print(jokes[randint(0, len(jokes))])
  228. return 0
  229. else:
  230. print("Thats ok. Bye!")
  231. return 0
  232. else:
  233. print("That sounds cool!")
  234. then = input("would you like to tell me a joke? ")
  235. if("yes" in then):
  236. print(jokes[randint(0, len(jokes))])
  237. return 0
  238. else:
  239. print("Thats ok. Bye!")
  240. return 0
  241. else:
  242. next = input("Thats cool. Whats up? ")
  243. if("nothing" in next):
  244. print("Thats ok! I love doing nothing too")
  245. then = input("would you like to tell me a joke? ")
  246. if("yes" in then):
  247. print(jokes[randint(0, len(jokes))])
  248. return 0
  249. else:
  250. print("Thats ok. Bye!")
  251. return 0
  252. else:
  253. print("That sounds cool!")
  254. then = input("would you like to tell me a joke?")
  255. if("yes" in then or "yeah" in then):
  256. print(jokes[randint(0, len(jokes))])
  257. return 0
  258. else:
  259. print("Thats ok. Bye!")
  260. return 0
  261.  
  262. functionsAvailable = ["hangman", "guess a number", "calculator", "rock paper scissors", "name generator", "conversation", "exit"]
  263. def processInput(answer):
  264. if(answer == "hangman"):
  265. hangman()
  266. elif(validInput(answer, ["guess a number", "guess"])):
  267. guessNum()
  268. elif(answer == "calculator"):
  269. calc()
  270. elif(validInput(answer, ["rock paper scissors", "rps"])):
  271. rps()
  272. elif(validInput(answer, ["name generator", "name"])):
  273. name()
  274. elif(validInput(answer, ["lets have a conversation", "convo", "conversation", "How are you?"])):
  275. convo()
  276. else:
  277. default()
  278.  
  279. def validInput(ui, valid):
  280. for i in range(len(valid)):
  281. if(ui == valid[i]):
  282. return True
  283. return False
  284.  
  285. def main():
  286. greet()
  287. while True:
  288. print("Here are the games available to you: ")
  289. for i in functionsAvailable:
  290. print(i)
  291. answer = input("(What will you say?) ")
  292. if(answer == "exit"):
  293. print("goodbye!")
  294. break
  295. else:
  296. print("_____________________________________")
  297. processInput(answer)
  298. print("_____________________________________")
  299.  
  300.  
  301. # DON'T TOUCH! Setup code that runs your main() function.
  302. if __name__ == "__main__":
  303. main()
Add Comment
Please, Sign In to add comment