Unsure of the cause of keyerrors which are occurring during each of the possible outcomes of music platforms. Im unsure of the correct syntax to multiply streams by the data found in the row of the corresponding chosen platform
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=int(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: (Case Sensitive! Please type name as it appears above) ")
if platform == "Spotify":
for row in csvreader:
print("Spotify will pay you $" + row["Spotify"] + " per stream")
print("You would earn $" + streams*row["Spotify"])
elif platform == "Apple Music":
for row in csvreader:
print("Apple Music will pay you $" + row["Apple Music"] + " per stream")
print("You would earn $" + streams*row["Apple Music"])
elif platform == "Google Play Music":
for row in csvreader:
print("Google Play Music will pay you $" + row["Google Play Music"] + " per stream")
print("You would earn $" + streams*row["Google Play Music"])
elif platform == "Deezer":
for row in csvreader:
print("Google Play Music will pay you $" + row["Deezer"] + " per stream")
print("You would earn $" + streams*row["Deezer"])
elif platform == "Pandora":
for row in csvreader:
print("Google Play Music will pay you $" + row["Pandora"] + " per stream")
print("You would earn $" + streams*row["Pandora"])
elif platform == "Amazon Music Unlimited":
for row in csvreader:
print("Google Play Music will pay you $" + row["Amazon Music Unlimited"] + " per stream")
print("You would earn $" + streams*row["Amazon Music Unlimited"])
elif platform == "Tidal":
for row in csvreader:
print("Google Play Music will pay you $" + row["Tidal"] + " per stream")
print("You would earn $" + streams*row["Tidal"])
else:
print("Invalid Input")
```

Aucun commentaire:
Enregistrer un commentaire