mercredi 2 décembre 2020

Using Python inputs to do calculations with a CSV file [closed]

sample of the csv file

I want to create a program which takes user input and calculates how much a person would earn per stream on a variety of streaming services. I'm unsure if this is the correct method to go about it because I get key errors. Im not sure if its the if statements which are the issue or if its the cdv reader

import csv

filename = "paymentperstream.csv"
with open(filename, 'r') as csvfile: 
    csvreader = csv.DictReader(csvfile)
    fieldnamesVariable = "'Spotify', 'Apple Music', 'Google Play Music', 'Deezer', 'Pandora', 'Amazon Music Unlimited', 'Tidal'"

    streams=input("How many streams would you like to calculate: ")
    print("The options of streaming services are " + fieldnamesVariable)
    platform=input("What platform would you like to calculate your streams on: ")
    
    if platform == "Spotify":
        for row in csvreader:
            print("Spotify will pay you $" + row["Spotify"] + " per stream")
            print("You would earn $" + streams*row["Spotify"])

Aucun commentaire:

Enregistrer un commentaire