Advertisement
namchef

py4inf_ch2

Sep 22nd, 2011
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.34 KB | None | 0 0
  1. ## ex. 2.2
  2. ## Write a program that uses raw_input to prompt a user for their name and then welcomes them.
  3. name = raw_input('What is your name? \n')
  4. print "Hello ", name
  5.  
  6.  
  7. ## ex. 2.3
  8. ## Write a program to prompt the user for hours and rate per hour to compute gross pay.
  9. ## Enter Hours: 35
  10. ## Enter Rate: 2.75
  11. ## Pay: 96.25
  12.  
  13. hours = raw_input('Enter hours \n')
  14. while hours.isdigit()==False:
  15.     hours = raw_input('Please enter a number for hours \n')
  16. rate = 2.75
  17. pay = float(hours)*rate
  18. print "Pay ", round(pay,2)
  19.  
  20.  
  21. ## ex. 2.4
  22. ## Assume that we execute the following assignment statements:  
  23. ## width = 17
  24. ## height = 12.0
  25. ## For each of the following expressions, write the value of the expression and the type (of the value of the expression).
  26. ## 1.  width/2
  27. ## 2.  width/2.0
  28. ## 3.  height/3
  29. ## 4.  1 + 2 * 5
  30.  
  31. width  = 17
  32. height = 12.0
  33. print 'width/2=',width/2
  34. print 'width/2.0=',width/2.0
  35. print 'height/3=',height/3
  36. print '1+2*5=', 1+2*5
  37.  
  38.  
  39. ## ex. 2.5
  40. ## Write a program which prompts the user for a Celsius temperature, convert the temperature to Fahrenheit and print out the converted temperature.
  41.  
  42.  
  43. tempC=raw_input('Tell me the temperature in Celsius \n')
  44. while tempC.isdigit()==False:
  45.     tempC=raw_input('The temperature must be a number \n')
  46. print 'The temperature in Fahrenheit is ', float(tempC)*9/5+32
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement