jeudi 29 octobre 2015

Processing two text files into a python matrix

A chocolate company has decided to offer discount on the candy products which are produced 30 days of more before the current date. I have to have a matrix as a print result where the program reads through 2 files, one being the the cost of the different candies of different sizes, and another being the threshold number of days after which the discount is offered. So in this question the two text files look something like this

candies.txt

31 32 19 11 15 30 35 37
12 34 39 45 66 78 12 7
76 32 8 2 3 5 18 32 48
99 102 3 46 88 22 25 21
fd zz er 23 44 56 77 99 
44 33 22 55 er ee df 22

and the second file days.txt

Discount at days = 30

It should print

      $  $  $         
$                $  $ 
      $ $ $ $  $      
       $       $  $  $ 
?  ?  ? $       
      $     ?  ?  ?   $      

So basically, everywhere the number is under 30(which is the input from days.txt) it should print a "$" sign and everywhere it is more than the number(30 in our case) it should just print spaces in their place. We also have an anomally, where we have the english alphabets in the candies.txt matrix and since we are looking for numbers to check the price and not letters, it should print a "?" sign in their place as it is not recognized.

Here is what I am trying to do.

def candyShop(candy, price):
    try:
        candyfile = open("candes.txt", "r")
        readCategory = process_file(candyfile)
        if readCategory str.isdigit():
            if readCategory > 30:
                print("$")
        elif:
            print("?")
        else:
            print("")

    return candyShop()

Aucun commentaire:

Enregistrer un commentaire