Я пытаюсь создать программу, которая умножает пользовательский ввод (потоки) на данные из списка, указанного в начале кода. В нем говорится, что объект типа не может быть подписан и в назначении есть несовместимые типы.
services = "'Spotify', 'Apple Music', 'Google Play Music', 'Deezer', 'Pandora', 'Amazon Music Unlimited', 'Tidal'" #variable of the row names
possiblePayment = [0.00318,0.00563,0.00551,0.00436,0.00151,0.01196,0.00989]
possiblePayment = float
streams=input("How many streams would you like to calculate: ") #user input
streams=int
print("The options of streaming services are " + services) #gives user the options of streaming services they can choose from
platform=input("What platform would you like to calculate your streams on: (Case Sensitive! Please type name as it appears above) ") #user chooses service
if platform == "Spotify":
print("Spotify will pay you $" + str(possiblePayment[0]) + " per stream") #if the user chooses Spotify, take data from row 2 (the row with spotify in it) of the file
print("You would earn $" + str(streams*possiblePayment[0])) #multiplies "streams" by the data in row 2 of the file (DOES NOT WORK, HERE IS WHERE THE ERRORS OCCUR)
elif platform == "Apple Music":
print("Apple Music will pay you $" + str(possiblePayment[1]) + " per stream") #see above
print("You would earn $" + str(streams*possiblePayment[1]))
elif platform == "Google Play Music":
print("Google Play Music will pay you $" + str(possiblePayment[2]) + " per stream")
print("You would earn $" + str(streams*possiblePayment[2]))
elif platform == "Deezer":
print("Deezer will pay you $" + str(possiblePayment[3])+ " per stream")
print("You would earn $" + str(streams*possiblePayment[3]))
elif platform == "Pandora":
print("Pandora will pay you $" + str(possiblePayment[4]) + " per stream")
print("You would earn $" + str(streams*possiblePayment[4]))
elif platform == "Amazon Music Unlimited":
print("Amazon Music Unlimited will pay you $" + str(possiblePayment[5]) + " per stream")
print("You would earn $" + str(streams*possiblePayment[5]))
elif platform == "Tidal":
print("Tidal will pay you $" + str(possiblePayment[6]) + " per stream")
print("You would earn $" + str(streams*possiblePayment[6]))
else:
print("Invalid Input") #if they dont give the name of a streaming service
это количество потоков, которые получает песня. это не может быть поплавок, потому что вы не можете транслировать песню наполовину
Вы имеете в виду использовать streams=int(input("How many streams would you like to calculate: "))
?
Нашел две проблемы в вашем коде:
possiblePayment
в строке 2 заменяется логическим значением в строке 3.streams=int
Я переименовал логическое значение в ispossible
и обернул входные потоки с помощью int
Код:
services = "'Spotify', 'Apple Music', 'Google Play Music', 'Deezer', 'Pandora', 'Amazon Music Unlimited', 'Tidal'" #variable of the row names
possiblePayment = [0.00318,0.00563,0.00551,0.00436,0.00151,0.01196,0.00989]
ispossible = float
streams=int(input("How many streams would you like to calculate: ")) #user input
print("The options of streaming services are " + services) #gives user the options of streaming services they can choose from
platform=input("What platform would you like to calculate your streams on: (Case Sensitive! Please type name as it appears above) ") #user chooses service
if platform == "Spotify":
print("Spotify will pay you $" + str(possiblePayment[0]) + " per stream") #if the user chooses Spotify, take data from row 2 (the row with spotify in it) of the file
print("You would earn $" + str(streams*possiblePayment[0])) #multiplies "streams" by the data in row 2 of the file (DOES NOT WORK, HERE IS WHERE THE ERRORS OCCUR)
elif platform == "Apple Music":
print("Apple Music will pay you $" + str(possiblePayment[1]) + " per stream") #see above
print("You would earn $" + str(streams*possiblePayment[1]))
elif platform == "Google Play Music":
print("Google Play Music will pay you $" + str(possiblePayment[2]) + " per stream")
print("You would earn $" + str(streams*possiblePayment[2]))
elif platform == "Deezer":
print("Deezer will pay you $" + str(possiblePayment[3])+ " per stream")
print("You would earn $" + str(streams*possiblePayment[3]))
elif platform == "Pandora":
print("Pandora will pay you $" + str(possiblePayment[4]) + " per stream")
print("You would earn $" + str(streams*possiblePayment[4]))
elif platform == "Amazon Music Unlimited":
print("Amazon Music Unlimited will pay you $" + str(possiblePayment[5]) + " per stream")
print("You would earn $" + str(streams*possiblePayment[5]))
elif platform == "Tidal":
print("Tidal will pay you $" + str(possiblePayment[6]) + " per stream")
print("You would earn $" + str(streams*possiblePayment[6]))
else:
print("Invalid Input") #if they dont give the name of a streaming service
почему
streams=int
? int - это класс. вы потеряете входное значение, если назначите класс этой переменной.