Advertisement
Guest User

p2pu.org | Python Programming | Task 2

a guest
Dec 29th, 2011
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.14 KB | None | 0 0
  1. # Exercises from:
  2. # http://p2pu.org/en/groups/python-programming-101/content/variables-expressionss-and-statements/
  3. #
  4. # Task:         Variables, expressions, and statements
  5. # Exercises:    2.2 - 2.5
  6. #
  7. # User: ulf_st
  8. # Date: 29.12.2011
  9.  
  10. # Exercise 2.2
  11. ################
  12. name = raw_input("Please tell me your name: ")
  13. print "Hello " + name
  14.  
  15. # Exercise 2.3
  16. ################
  17. hours = float(raw_input("Enter Hours: "))
  18. rate = float(raw_input("Enter Rate: "))
  19. pay = str(rate*hours)
  20. print "Pay: " + pay
  21.  
  22. # Exercise 2.4
  23. ################
  24. width = 17
  25. height = 12.0
  26.  
  27. print width/2           # Solution: 8 | Type Integer
  28. print type(width/2)
  29.  
  30. print width/2.0         # Solution: 8.5 | Type float
  31. print type(width/2.0)
  32.  
  33. print height/3          # Solution: 4.0 | Type float
  34. print type(height/3)
  35.  
  36. print 1+2*5             # Solution: 11 | Type Integer
  37. print type(1+2*5)
  38.  
  39. # Exercise 2.5
  40. ################
  41. fahr2cel = float(raw_input("Enter Fahrenheit temperature: "))
  42. celsius = str((fahr2cel - 32) * 5.0 / 9.0)
  43. print "In Celsius: " + celsius
  44.  
  45. cel2fahr = float(raw_input("Enter Celsius temperature: "))
  46. fahrenheit = str((cel2fahr + 32) / 5.0 * 9.0)
  47. print "In Celsius: " + fahrenheit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement