Home > Back-end >  IF statement and For
IF statement and For

Time:10-06

I'm a very, very n00b developper learning Python at university (I started a few weeks ago really) and I'm on my first assignment. Everything's going well, except one thing and i just can't figure it out. Or rather, I know what the problem is, but I can't find the solution. In short, I need to ask the user to input a number, and if number is 0, then the programs shows a message and stops there. Otherwise, it goes on with asking more info and uses For loops. My question is: How do I insert lines that are not part of the IF (user has entered 0) but also not part of any For loops (i don't want these lines repeated). I'm not sure if that makes any sense.

python code

basically i want the last print to be shown if the user has entered more than 0 in the beginning, but not be shown if the user has entered 0. I'm not showing the actual code, since it's a uni assignment, but the screenshot shows exactly the issue I'm having with the real code :) Thanks for your help!! (also, sorry that it's actually a link, because i don't have enough points yet to embed the image).

CodePudding user response:

This one is pretty easy. Im not that great at python yet but i just tested it and it works as intended.

def isZero(val):
    if val==0:
        print('bye')
        quit()      

title = int(input('enter a number'))
ZeroCheck = isZero(title)
while title>0:
    title = int(input('enter a number'))
    isZero(title)
        
            
        
  • Related