Bunmite

FREELANCE TRANSLATION CALCULATION

May 3rd, 2020
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.23 KB | None | 0 0
  1. #THIS PROJECT COUNTS THE NUMBER OF WORDS/CHARACTERS IN A TEXT AND CALCULATES THE TRANSLATION PRICE ACCORDINGLY
  2.  
  3. # guide the user on how to input file path correctly
  4. print("kindly input your file path in this format: " + "\n" + "\n" +
  5.           'C:\\Users\\user\\Desktop\\filename.extension')
  6.  
  7. print("\n" + "the above format was just an example")
  8.  
  9. while True:
  10.     try:
  11.         count = 0
  12.  
  13.  
  14. # open file and read
  15.         with open(input(),encoding='utf8', newline='\n') as filename:
  16.                    
  17.  
  18. # splits each line into words
  19.                 words = filename.read().split()
  20.  
  21.    
  22.    
  23. # counts each word in individual lines
  24.                 count = count + len(words);
  25.         print ("\n" + "Number of words present in your file is  " + str(count))
  26.  
  27.  
  28. #  a translator charges average of 0.04 USD per word for translation
  29.         price = 0.04 * int(count)
  30.         print("\n" + f"to translate your {count} words, its gonna cost you   {price} dollars")
  31.        
  32.         break
  33.        
  34.     except FileNotFoundError:
  35.         print("\n kindly input the correct file path \n")
  36.    
  37.     except UnicodeDecodeError:
  38.         print("\n The file should have a .txt entension \n")
  39.    
  40.     except:
  41.         break
  42. # end of code
Add Comment
Please, Sign In to add comment