Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Loop question
#1
Extremely new to programming, and I am trying to get this whole loop thing down. I am doing one of the assignment's that I am sure you all have probably seen a hundred times; I am doing the gross pay and over time pay calculator. I have everything done with the exception of getting the program to loop with the user ability to stop it.

With the example below I got the program to loop for me but now it seems like it just skips the if statement and moves right into the else statement.

Example:
while a ==0:
   n = input("Enter employee's name or press 0 to quit:")
   print()
   if n==0:
        exit
Again, very new to this so any and all help is much appreciated.
Reply
#2
input returns a string (in python3) so what you'd want is:
if n == "0":
   break
or similar.
Reply
#3
Thank you! is it the break that made a difference or was it "0" that made the difference?
Reply
#4
It's '0'. As @Mekire said, input() returns a string so you compare 'n' which is string against an integer.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Many iterations for loop question adesimone 9 1,819 Nov-12-2022, 07:08 PM
Last Post: deanhystad
  Please check whether the code about the for loop question is correct. (SyntaxError) lilliancsk01 10 2,568 Nov-08-2022, 01:25 PM
Last Post: deanhystad
  Beginner Python Question: FIzz Buzz using while loop camoyn13 2 1,789 Sep-20-2022, 09:00 AM
Last Post: deanhystad
  Repeat question (for loop) rs74 7 6,458 Jun-17-2020, 03:17 PM
Last Post: rs74
  Question about running comparisons through loop from input value Sunioj 2 2,398 Oct-15-2019, 03:15 PM
Last Post: jefsummers
  while loop question Tripler 4 2,939 Jul-24-2018, 06:37 AM
Last Post: buran
  Question about loop Pires 4 3,547 Jul-23-2017, 03:01 AM
Last Post: Pires
  Udacity while loop question liquidmetalrob 6 5,335 Jul-21-2017, 02:56 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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