Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # ohjelma tasaa kulut, joita tekstitiedostossa on annettu
- def totalcalc(dict):
- summa = 0
- for i in dict:
- summa = summa + float(dict[i])
- return summa
- def main():
- tiedosto = input("Enter the name of the file: ")
- lahtotied = open(tiedosto, "r")
- dict = {}
- testi = {}
- for rivi in lahtotied:
- test = rivi.strip()
- name, sum = test.split(":")
- if name not in dict:
- dict[name] = sum
- elif name in dict:
- dict[name] = float(dict[name]) + float(sum)
- people = len(dict)
- total = totalcalc(dict)
- keskiarvo = total/people
- print("Total costs: {:.2f}e".format(total))
- print()
- for i in dict:
- dict[i] = float(dict[i]) - keskiarvo
- for i in dict:
- if dict[i] < -0.05:
- t = dict[i] * -1
- print(i + " has paid {:.2f} in the following amounts: ".format(t))
- print(i + " needs to pay {:.2f}e.".format(t))
- print()
- elif dict[i] > 0.05:
- print(i + " has paid {:.2f} in the following amounts: ".format(dict[i]))
- print(i + " needs to receive {:.2f}e.".format(dict[i]))
- print("")
- else:
- print(i + " has paid {:.2f} in the following amounts: ".format(dict[i]))
- print("No transfers needed.")
- print()
- print(testi)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement