Ask your own question, for FREE!
Computer Science 6 Online
OpenStudy (anonymous):

Python: In my program, I want to get the value of each donation the user enter.

OpenStudy (anonymous):

#enter number of doantions don = input("How many donations received? ") for i in range(0, len(don)): #Value of each separate donation given don[i] = input("Value of donation: ) This is my code so far but i keep getting an TypeError. pledges[i] = input("Value is: ") <- error line TypeError: 'str' object does not support item assignment If there are 3 donations. I want to get the value of each donation separately but,' I am not able to do that when i want to iterate through the elements. Is the method wrong, for trying to get the input of the elements in don, to get there values?

OpenStudy (rsmith6559):

Wouldn't that problem line convert the (I assume) number entered to float? pledges[ i ] = float( input( "Value is: " ) ) I also don't see pledges declared anywhere: pledges = []

OpenStudy (anonymous):

oh sorry i had changed the input variable to 'don' donations would be an integer and the values should be floats but i was testing to see if it would at least give me ex. 3 separate donation values because I entered that the user was given 3 donations.

OpenStudy (agent47):

``` don = input("How many donations received?") # you enter a number ``` Don is now an integer, so you can't use len(don) anymore, change that to don. Also you can just say range(don), which is the same as range(0, don) Now initialize your pledge amounts ``` pledge_amounts = [] ``` Now ask the user for amount and append that to pledge amounts. ``` for i in range(don): pledge_amounts.append(input("Value of donation: ")) ```

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Latest Questions
Mari103: How to pop out like a Jacc In the box
7 hours ago 0 Replies 0 Medals
Breathless: Spooky witch but cute
14 hours ago 3 Replies 0 Medals
Arriyanalol: help
14 hours ago 10 Replies 2 Medals
Arriyanalol: @tinydinoUwU stop trying to find a argument u blad lil boy
1 day ago 5 Replies 4 Medals
Jaded012023: Please tell me what you all think of this song
17 hours ago 6 Replies 1 Medal
Arriyanalol: bro how
17 hours ago 2 Replies 3 Medals
Arriyanalol: cant wait for the new bluey movie in 2027
1 day ago 12 Replies 2 Medals
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!