Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help with homework
#1
I need help with creating a manually generated float list.

Results should look like this

[Image: unknown.png]

Thanks!
Reply
#2
What have you tried?
Post your attempt (in code tags) and explain the (incorrect) results you get. Or post full error traceback message (in error tags) if you get errors.
Reply
#3
Hi,

I don't know where to begin. I got the beginning line, but that's it.

print("Sales Tax Calculator")
print("")
print("ENTER ITEMS (ENTER 0 TO END)")
Reply
#4
It looks like there will need to be a repetition (asking user to enter values), so a loop is in place.
Reply
#5
print("Sales Tax Calculator")
print("")
print("ENTER ITEMS (ENTER 0 TO END)")

cost_of_item = float(input("Cost of item: "))

while(cost_of_item > 0):
    print()
    print("Cost of item: ", cost_of_item)
issue with this code is that the results are infinite. I want to have separate instances as shown in the image.
Reply
#6
That's a good start.
The loop cycles infinitely because the condition in while loop never changes. Make sure user can input a new number afer each iteration, so that cost_of_item is updated, and while() can check against new condition.
Reply
#7
How do I reset?

print("Sales Tax Calculator")
print("")
print("ENTER ITEMS (ENTER 0 TO END)")

cost_of_item = 1

while(cost_of_item > 0):
    cost_of_item = float(input("Cost of item: "))
    print()
    print("Cost of item: ", cost_of_item)
So I have separate numbers - I want to build an aggregate list.
Reply
#8
Any code you write after the while loop will be executed when the loop exits.
As for the calculations, you will need to store the values after each loop iteration in a proper data type / container.
If you read about some Python basics you will easily figure this out.
Reply
#9
Hi,

I don't know which tool(code) I need to use.
Reply
#10
Hello,
reading a basic tutorial will probably be enough to learn all you need to solve this task.
Make sure you learn about data types (and basic operations on them), conditional statements and loops.
It really doesn't take too much effort to learn the basics, but it's probably not a single afternoon task if you are a beginner.
There is plenty of resources online, as well as in the Tutorials section of our forum.
If you have more questions or face coding issues feel free to post back.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020