samedi 7 juillet 2018

Python writing a .txt file

print('Welcome, I am Sam. I am ABMs personal assistant, today we will be pooling tips together!')

file = open(“tipsdate.txt”,”w”) 

name=str(input('Who do I have the pleasure of working with? '))

tips=int(input('How many tips did we collect today? '))
workers=int(input('How many people worked today? '))
cars=int(input('How many cars did we park today?'))

if workers == 1:
        print('Worker 1 earned $',tips)
elif workers == 2:
        a=int(input('How many hours did worker 1 work? '))
        b=int(input('How many hours did worker 2 work? '))
        totalhrs=a+b
        tipsa= (a/totalhrs)* tips
        tipsb= (b/totalhrs)*tips
        print('Worker one earned $',tipsa)
        print('Worker two earned $',tipsb)
elif workers == 3:
        a=int(input('How many hours did worker 1 work? '))
        b=int(input('How many hours did worker 2 work? '))
        c=int(input('How many hours did worker 3 work? '))
        totalhrs=a+b+c
        tipsa= (a/totalhrs)* tips
        tipsb= (b/totalhrs)*tips
        tipsc= (c/totalhrs)*tips
        print('Worker one earned $',tipsa)
        print('Worker two earned $',tipsb)
        print('Worker three earned $',tipsc)
elif workers == 4: 
        a=int(input('How many hours did worker 1 work? '))
        b=int(input('How many hours did worker 2 work? '))
        c=int(input('How many hours did worker 3 work? '))
        d=int(input('How many hours did worker 4 work? '))
        totalhrs=a+b+c+d
        tipsa= (a/totalhrs)* tips
        tipsb= (b/totalhrs)*tips
        tipsc= (c/totalhrs)*tips
        tipsd= (d/totalhrs)*tips
        print('Worker one earned $',tipsa)
        print('Worker two earned $',tipsb)
        print('Worker three earned $',tipsc)
        print('Worker four earned $', tipsd)
elif workers > 4:
    print('I am not programmed to calculate tips beyond 4 workers, I am a work in progress!')

cartips=tips/cars
print('Our tips per car average today was $ ',cartips)
file.close() 


print('Thank you for your help',name,'I hope we work together again soon! :) ')

Hi there, thanks for taking your time to help me. I am an amateur, self taught python coder. I am trying to figure out how to write a .txt file with conditional loops and various user inputs. I realize that this is noobie, but how does one allow for all this information to be stored in a .txt file?

This is for my valet parking job, just a fun side project to help me get more experience! Thank you. Any suggestions are welcome too, to improve my code - I realize its probably screams noob!

Aucun commentaire:

Enregistrer un commentaire