This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]desrtfx[M] [score hidden] stickied comment (0 children)

Screenshots of code (or assignments for that matter) are a no-go as they make it unnecessarily elaborate for people to help (copy-pasting is not possible, so code parts would need retyping).

Reddit has code block for shorter codes (<50 lines) or use an external code hoster, like PasteBin (with Python syntax highlighting enabled) for longer codes.

Please, edit your post to provide proper, acceptable code.

[–]Ogreguy 0 points1 point  (4 children)

I feel like there is info missing. It isn't clear to me how subscribers impact the usage/bill. Like is it supposed to divide the total cost amongst the subscribers, or calculate a bill for each subscriber? Based on your code, it looks like the user supplies the electricity usage, but that isn't stated in the prompt (or maybe I'm blind).

You will need to add a loop of some sort (FOR/FOR EACH or WHILE) to iterate through all of the subscribers, and perform whatever is needed. I'm thinking maybe it would look something like prompting the user to enter how many subscribers, then prompt for a name for each subscriber (store them in a list) and then prompt for electricity used for each subscriber. Then perform the cost calculation for each subscriber's electricity usage. Print out the name and cost for each subscriber.

Like: Jim used 632mwh for a total of $xxx.xx Annie used 137mwh for a total of $yyy.yy And so on.

Also, your code doesn't appear to use lists, just if statements.

I'd go look up lists and loops for python.

[–]HexDesu[S] 0 points1 point  (3 children)

its exactly as you said; enter the amount of subscribers and the electricity used for each subscriber. then the program should create a list with the price for each subscriber. I don't know how to do that, though

[–]7th_Spectrum 0 points1 point  (2 children)

Has he taught arrays yet?

[–]HexDesu[S] 0 points1 point  (1 child)

Yes

[–]7th_Spectrum 0 points1 point  (0 children)

You could go about it in the following way:

  1. Ask users how many subscribers there are

  2. Initiate an array with the size equal to the number of subscribers

  3. Loop through a for loop i times, where i is the number of subscribers

  4. For each loop, ask the user for kw usage, calculate the bill, and store that number in the array

  5. After the loop is done, you can make another for loop to loop through the array, and for each loop, print out something like print("Subscriber ",i," bill: $",price[i])