Python Forum
Python calculator help but not using while loop with true, any flags variable ,break
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python calculator help but not using while loop with true, any flags variable ,break
#11
Quote:no that code not work requirement is if num2 = 0 (divisor is zero), calculator should prompt user again for num2 until it is non zero and displays correct output (num1 /num2) and then exit the loop with op = (please choose ooperator or q to quit)

You haven't tried it, that is exactly what deanhystad's code does.
just added a print statement at end:
num2 = 0

while num2 == 0:
    num2 = float(input('\nenter a non-zero divisor '))

print(f"num2: {num2}")
Output:
enter a non-zero divisor 0 enter a non-zero divisor 0 enter a non-zero divisor 12 num2: 12.0
Reply
#12
that code just goes in loop i tried it on my linux machine it is not giving result and also i cannot break out of loop break
Reply
#13
It does what you want. You must be using it wrong
Reply
#14
Deanhystad Wrote:It does what you want. You must be using it wrong

And I showed the actual results when I ran it. It works as stated.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Calculator Loop Help dock1926 3 3,855 Jun-23-2021, 10:05 PM
Last Post: HereweareSwole
  Weight loss calculator loop error drogers10940 7 14,517 Feb-14-2021, 12:36 AM
Last Post: Larz60+
  while loop on a calculator missus_brown 3 15,060 Feb-10-2019, 08:19 PM
Last Post: ichabod801
  i need help in fixing my scientific calculator coding : (, im using python 3.5.5 hans77 1 4,152 Oct-17-2018, 03:26 AM
Last Post: stullis
  python age calculator need to find the number of years before they turn 100 not using orangevalley 4 9,929 Mar-26-2018, 04:44 AM
Last Post: PyMan
  while true loop candylicious 3 4,180 Nov-06-2017, 06:36 PM
Last Post: gruntfutuk

Forum Jump:

User Panel Messages

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