I have a question about programming (python) !:
I don't understand what to do…
Calculator hacking
Enough played, now it's getting serious! You surely still have the code for the "calculator" from the last time, the one with the while loop. Copy the code into your polite Jupyter notebook, because it will form the basis for the following tasks:
A calculator needs a lot of electricity, so you shouldn't use it too often. Program the calculator so that it allows a maximum of three bills and then ends automatically.
Do you know what I'm there or how I can do it?
I appreciate any help!
With the many details you give in your question:
Create counter variable
Carry out calculation
Increase counter variable by 1
If counter variable go to step 2
The End
I don't know exactly what the code looks like, but I guess there's a while loop, and while it's true the program is running.
You now have to create a counter variable that is incremented by 1 after each calculation and then you need, for example, an if condition that sets the while loop to false or ends the program as soon as the count loop is 3.
At the beginning of each calculation you have to count up a counting variable (1, 2, …). At the end of each calculation you have to check how big this variable is. If it is 3, you can exit the program with exit ().
Then tell me first where your problem is:
Protipp: Change the line with "While" and add a condition there that it only runs three times. You need a count variable then
You surely still have the code for the "calculator" from the last time, the one with the while loop.
No, I don't have this code.
And without knowing the code, you can't be helped further to what extent you could change it accordingly. As long as we don't know the code, we can only give rough, general information.
Depending on how the "calculator" was programmed, you can simply replace a while loop with a for loop with 3 passes. For example, replace a corresponding "while True:" with "for k in range (3):" so that the loop is only run three times.