Advertisement
pleabargain

python 3 the hard way exe 24 focus on the tuple error

May 4th, 2013
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.34 KB | None | 0 0
  1. #from http://learnpythonthehardway.org/book/ex24.html
  2. # narrowed down the code around the tuple problem
  3. # the original code from the site is written for Python 2.7
  4. #below is written for python 3.3
  5. def secret_formula(started):
  6.     jelly_beans= started *500
  7.     jars = jelly_beans / 1000
  8.     crates = jars / 100
  9.     return jelly_beans, jars, crates
  10.  
  11. start_point = 10000
  12. beans, jars, crates = secret_formula(start_point)
  13.  
  14. print ("With a starting point of: {}".format(start_point))
  15. print ("We'd have {} beans, {} jars, and {} crates.".format(beans, jars, crates))
  16.  
  17. start_point = (start_point /10)
  18.  
  19. print ("We can also do that this way: ")
  20. print ("Start point",start_point)#testing what interpreter sees
  21. print ("secret formula", secret_formula)#testing what interpreter sees
  22. print ("We'd have {} beans, {} jars, and {} crates.".format (secret_formula(start_point)))
  23. #error text
  24. """
  25. With a starting point of: 10000
  26. We'd have 5000000 beans, 5000.0 jars, and 50.0 crates.
  27. We can also do that this way:
  28. Start point 1000.0
  29. secret formula <function secret_formula at 0x0000000003D1D1E0>
  30. Traceback (most recent call last):
  31.  File "C:/Python33/PTHW24a.py", line 18, in <module>
  32.    print ("We'd have {} beans, {} jars, and {} crates.".format (int(secret_formula(start_point))))
  33. TypeError: int() argument must be a string or a number, not 'tuple'
  34. """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement