HELP: beginner python program, while loop

Okay so I am having issues with a programming activity in my class. This is my first programming class so we aren’t using anything very advanced in our codes. I have tried the problem based off an example he gave during class (I think he did it wrong) and I am unable to return the counted amount of the checks. Also unable to stop the while loop when the user inputs “Y” or “N” and returning the final output once the user inputs “N”, you can see this below. It’s like I understand what we are supposed to do, I just have a hard time knowing what and where to put things. Any help is appreciated. Below I attached the problem as well as what I have tried, the format should be similar to what I have already written. This program should utilize the while loop, but we have also learned if, else, elif, break, continue, so if needed those could be incorporated as well. Thank you!
PROBLEM:
Design a code using the Python programming language that utilizes an event-based iteration structure that will allow you to input the check number and the amount of money for which it was issued. It should compute the total number of checks issues as well as the total amount of money spent. It should display the total number of checks issued as well as the total amount for which those checks are issued as shown below.
Total Number of checks issued: xxx checks
Total Amount of Money Spent: $ xxxxxx.xx

MY CODE:

checkCount = 0
totalAmount = 0.0
keepGoing = True
while(keepGoing):
    checkNumber = int(input("Enter the check number ===> "))
    checkAmount = float(input("Enter the amount of the check ===> "))
    checkCount = checkCount + 1
    totalAmount = totalAmount + checkAmount
    print("The amount of checks you have entered is: ")
    userFeedback = input("Do you wish to enter more checks? (Y = yes, N = no): ")
    if (userFeedback == "No"):
        keepGoing = False


print("Total Number of checks issued: ", checkCount, "checks:")
print("Total Amount of Money Spent: $", format(totalAmount, ".2f"))

OUTPUT:
Enter the check number ===> 3678
Enter the amount of the check ===> 43.80
The amount of checks you have entered is:
Do you wish to enter more checks? (Y = yes, N = no): Y
Enter the check number ===> 3213
Enter the amount of the check ===> 33.60
The amount of checks you have entered is:
Do you wish to enter more checks? (Y = yes, N = no): N
Enter the check number ===>

Can you please provide a copy and paste of your code instead of a screenshot? It is very difficult to help from screenshots.


When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Okay! Thank you, I am new to this website and was not sure how to do that :slight_smile:

I think your only problem is that the text in the user prompt and the string you are checking against differ

1 Like

Okay yes I see that. That worked! However I still can’t seem to display the number of checks the user has entered following their input of the check number and check amount… Not sure if that makes sense. I THINK he wants the user to be able to input the check number such as “4321”, and then it should return the amount of checks that have been entered so far (1 check, 2 checks, and so on) His directions aren’t super clear sometimes, I asked him about it but he wasn’t very clear on explaining (no offense to him, super nice guy)

I’m seeing an output with the number of checks: https://repl.it/repls/NocturnalMiserlyTraining#main.py

I am talking about this part

Enter the check number ===> 5
Enter the amount of the check ===> 73
The amount of checks you have entered is: 
Do you wish to enter more checks? (Y = yes, N = no): 

when tells the user how many checks they have entered so far… my computer may be jacked up, who knows!

Oh, I thought you meant the final output.

This line is your issue… no number in the print statement.

Gotcha! Such a simple solution. Thanks so much!

Alright, so I already made a post about this exact question, but here I am asking about it again. The program I wrote used LISTS which landed me a fat 0 for the assignment because apparently we were not to use lists on this assignment. Fortunately for me I get to rewrite it. SO, I am supposed to use a count-based iteration structure, I can use the “for” statement, or both the “for” and “while” statements. But NOT just the “while” statement alone ( count based not event based). I do not know which combination would be most effective. I have attached my program but I do not think it is very good at all, the structure just seems bad to me. If anyone could give me some guidance on how I could make this look better, or how I could improve it I would appreciate it immensely. I have searched high and low for an example that doesnt include lists or some crazy stuff (I am a beginner so we use beginner things) but have had no luck at all.
Lastly, I would like to say again, I CANNOT use LISTS, thank you all in advance!

THE PROBLEM:

MY CODE:

fish=int(input("enter fish price ===> "))
corn=int(input("enter corn price ===> "))
steak=int(input("enter steak price ===> "))
asparagus=int(input("enter asparagus price ===> "))
for x in range (1,fish+1,1):
    total=x
for y in range(1,corn+1,1):
    total=x+y
for z in range(1,steak+1,1):
    total=x+y+z
for i in range(1,asparagus+1,1):
    total=x+y+z+i
print("Item Description   Item Price")
print("==============================")
print("Fish              $",fish)
print("Corn              $",corn)
print("Steak             $",steak)
print("Asparagus         $",asparagus)
print("Your Total Purchase:", total)

output:
enter fish price ===> 5
enter corn price ===> 5
enter steak price ===> 5
enter asparagus price ===> 5
Item Description Item Price

Fish 5 Corn 5
Steak 5 Asparagus 5
Your Total Purchase: 20