Unsure of the cause of invalid index types and unsure of how to fix them. Its complaining about strings and integer inputs. I want the code to multiply the user input (streams) by the data from the csv file which is also chosen by the user. For example How many streams would you like to calculate: 5 What platform would you like to calculate your streams on: Spotify You would earn: $0.0159 (5*0.00318) (0.00318 comes from the Spotify row of my CSV file)
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'"
rows = [" 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[2] + " per stream")
print("You would earn $" + streams*row[2])
elif platform == "Apple Music":
for row in csvreader:
print("Apple Music will pay you $" + row[3] + " per stream")
print("You would earn $" + streams*row[3])
elif platform == "Google Play Music":
for row in csvreader:
print("Google Play Music will pay you $" + row[4] + " per stream")
print("You would earn $" + streams*row[4])
elif platform == "Deezer":
for row in csvreader:
print("Google Play Music will pay you $" + row[5] + " per stream")
print("You would earn $" + streams*row[5])
elif platform == "Pandora":
for row in csvreader:
print("Google Play Music will pay you $" + row[6] + " per stream")
print("You would earn $" + streams*row[6])
elif platform == "Amazon Music Unlimited":
for row in csvreader:
print("Google Play Music will pay you $" + row[7] + " per stream")
print("You would earn $" + streams*row[7])
elif platform == "Tidal":
for row in csvreader:
print("Google Play Music will pay you $" + row[8] + " per stream")
print("You would earn $" + streams*row[8])
else:
print("Invalid Input")
```

Aucun commentaire:
Enregistrer un commentaire