Advertisement
Guest User

Untitled

a guest
Nov 25th, 2015
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.26 KB | None | 0 0
  1.  
  2. #20th-25th November 2015
  3. #Homework
  4.  
  5. #setting values of variables.
  6. def abcdx():
  7. print "a - Square"
  8. print "b - Rectangle"
  9. print "c - Triangle"
  10. print "d - Circle"
  11. print "x - Exit"
  12. #importing the function.
  13. from math import pi
  14. import sys
  15.  
  16. def chooseoperation(): #choosing which operation you want to use
  17. global choiceofoperation
  18. choiceofoperation = raw_input("Please tell me which operation you want to use.")
  19. choiceofoperation = choiceofoperation.lower()
  20. #for working out the square
  21. def square():
  22. print "You are working with a square"
  23. sidelength = float(raw_input("Please enter the length of a side of this square."))
  24. area = sidelength ** 2
  25. perimeter = sidelength * 4 #equation to figure out what you need
  26. print "The area of this square (with side length", str(sidelength) + ") is:", str(area), ", And the perimeter of this square is: ", str(perimeter)
  27. #working out of a square using def to set its own variables
  28. def rectangle():
  29. print "You are working with a rectangle"
  30. shortersidelength = float(raw_input("Please tell me the length of one of the two shorter sides."))
  31. longersidelength = float(raw_input("Please tell me the length of one of the two longer sides."))
  32. area = shortersidelength * longersidelength
  33. perimeter = (shortersidelength * 2) + (longersidelength * 2)
  34. print "The area of this rectangle (with shorter side length", str(shortersidelength) + ", and longer side length", str(longersidelength), "is:", str(area), "And the perimeter of this rectangle is:", str(perimeter)
  35. #working out for a triangle.
  36. def triangle():
  37. print "You are working with a triangle"
  38. longestlength = float(raw_input("Please tell me the length of the longest side of the triangle."))
  39. secondlongestlength = float(raw_input("Please tell me the length of the second longest side of the triangle."))
  40. thirdlongestlength = float(raw_input("Please tell me the length of the third longest (AKA shortest) side of the triangle."))
  41. area = (longestlength * secondlongestlength) / 2
  42. perimeter = longestlength + secondlongestlength + thirdlongestlength
  43. print "The area of this triangle (with longest length", str(longestlength) + ", second longest length", str(secondlongestlength), "and shortest length", str(thirdlongestlength) + "), is:", str(area), "And the perimeter of this triangle is:", str(perimeter)
  44. def circle():
  45. print "You are working with a circle!"
  46. radius = float(raw_input("Please give me the radius of the circle."))
  47. area = pi * (radius ** 2)
  48. circumference = pi * (radius * 2)
  49. print "The area of this circle (with the radius", str(radius) + ") is:", str(area), "And the circumference of this circle is:", str(circumference)
  50. def exit():
  51. print "Okay!"
  52. sys.exit()
  53.  
  54. while True:
  55.  
  56. chooseoperation()
  57.  
  58. while choiceofoperation not in ("a","b","c","d","x"):
  59. print "You did not make an acceptable choice."
  60. abcdx()
  61. chooseoperation()
  62.  
  63. if choiceofoperation == "a":
  64. square()
  65. elif choiceofoperation == "b":
  66. rectangle()
  67. elif choiceofoperation == "c":
  68. triangle()
  69. elif choiceofoperation == "d":
  70. circle()
  71. elif choiceofoperation == "x":
  72. print "Okay, exiting!"
  73. sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement