Advertisement
JHG

Exercises 2.2 - 2.5

JHG
Dec 7th, 2011
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.22 KB | None | 0 0
  1. # JHG
  2. # 12-07-2011
  3. # Exercise 2.2
  4. # Prompt the user for their name and welcomes them.
  5.  
  6. name = raw_input('Enter your name: ')
  7. print 'Hello ' + name
  8.  
  9. # JHG
  10. # 12-07-2011
  11. # Exercise 2.3
  12. # Prompt the user for hours and rate per hour and
  13. # compute the pay.
  14.  
  15. hours = raw_input('Enter Hours: ')
  16. rate = raw_input('Enter Rate: ')
  17. pay = int(hours) * float(rate)
  18. print 'Pay: ', round(pay, 2)
  19.  
  20. # JHG
  21. # 12-07-2011
  22. # Exercise 2.4
  23. # Determine the value of each expression
  24. # and type of the value.
  25.  
  26. width = 17
  27. height = 12.0
  28. value1 = width / 2
  29. value2 = width / 2.0
  30. value3 = height / 3
  31. value4 = 1 + 2 * 5
  32. print '1. width/2'
  33. print value1            # 8
  34. print type(value1)      # int
  35. print
  36. print '2. width/2.0'
  37. print value2            # 8.5
  38. print type(value2)      # float
  39. print
  40. print '3. height/3'
  41. print value3            # 4.0
  42. print type(value3)      # float
  43. print
  44. print '4. 1 + 2 * 5'
  45. print value4            # 11
  46. print type(value4)      # int
  47.  
  48. # JHG
  49. # 12-07-2011
  50. # Exercise 2.5
  51. # Ask the user for a Celsius temperature,
  52. # convert it to a Fahrenheit temperature.
  53.  
  54. celsius = raw_input('Enter Celsius temperature: ')
  55. fahrenheit = float(celsius) * 9.0 / 5.0 + 32
  56. print 'Fahrenheit temperature: ', round(fahrenheit, 2)
  57.  
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement