Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

if statement, going back and forth

i am new to python, but have programmed some structured text, and a tiny bit c++
now i am working on a problem using if statements and it doesnt seem to work the way i am used to

example code:

more_guests = 0
loop = bool; loop = False
ferdig = int; ferdig = 1
while loop == False:
    guests = []
    more_guests = 0
    if int(ferdig) == 1:
        guest = input("type in guest ")
        more_guests = int(input("done? 1 for yes 2 for no "))
        if int(more_guests) == 1:
          guests.append(guest)
          ferdig == 3
        elif int(more_guests) == 2:
            guests.append(guest)
            ferdig == 2
        else:
            print("unvalid answer, please use 1 or 2")
            ferdig == 1
    elif int(ferdig) == 2:
        ferdig = 1
    elif int(ferdig) == 3:
        print(guests)
    else:
        loop = True

ive tried making sure its an integer and so on, just keep getting stuck on done? 1 for yes 2 for no, it always loop me back to type in guest

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

while using structured text i often used this way of going back and forth, but i cant seem to understand it in python, maybe i should rather use case/switch?
anyways if anyone could help me understand if you can use the IF statement this way in python is highly appreciated

>Solution :

I think you wrote wrong operator.
ferdig == 1 just comparing value operator. So it’s return true(1) or false(0).

if you wnat to change the ferdig’s value you should write ferdig = 3 in if statement.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading