Advertisement
Morbo

adder-v2

Sep 15th, 2012
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. from sys import argv
  2. #from os.path import exists
  3.  
  4. script,arg1,arg2 = argv
  5.  
  6. #multiplies
  7. def multi(a,b):
  8.     return a*b
  9.  
  10. #reads a file, turns to integer, then closes.
  11. def read(a):
  12.     f1 = open(a)
  13.     c = int(f1.readline())
  14.     f1.close()
  15.     return c
  16.    
  17. #Turns b into a string, then write to a, then closes
  18. def write(a,b):
  19.     c = str(b)
  20.     f1 = open(a,'w')
  21.     f1.write(c)
  22.     f1.close()
  23.  
  24. print '''We're going to take some numbers,
  25. write them to some files,
  26. then read those files,
  27. then multiply those numbers,
  28. then write to another file.\n'''
  29.  
  30. num1 = int(raw_input('First number: '))
  31. num2 = int(raw_input('Second number: '))
  32.  
  33. write(arg1,num1)
  34. write(arg2,num2)
  35.  
  36. print 'Now let\'s open those files and multiply the numbers together then save to a new file'
  37. new_f = raw_input('New file name?: ')
  38.  
  39. ans = multi(read(arg1),read(arg2))
  40.  
  41. write(new_f,ans)
  42.  
  43. #retrives answer
  44. print read(new_f)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement