#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2017
    Posts
    85
    Rep Power
    2

    [Python 3] While Loop Name Script not Works..., Help Needed!


    Hey Python Programmers...

    I try to create an script you must typ an name, to find his hobby...
    This script must be run to typ all names minimal 1x... but it doesn't...

    So this i my script, writting in python 3 on windows 10:
    Code:
    # Mijn Eerste Collectie:
    Run = True
    
    HOBBYS = {'Jamie' : 'Natuurkunde',
            'Ellister' : 'Darten',
            'Sander' : 'Lezen',
            'John' : 'Muziek',
            'Rob' : 'Speelgoed'}
    
    while Run:
    
        NAMES = str(input('Typ een naam om zijn hobby te weten: '))
    
        if NAMES in HOBBYS:
            print(HOBBYS[NAMES])
        elif (HOBBYS == HOBBYS):
            Run = False
        else:
            print('Deze naam bstaat niet!')


    Sorry for my dutch, i am an dutch user and living in holland... but for this script,
    it don't works perfectly...

    The problem is thad i want, if you get all the five names typed and get all hobbys (or
    reather the awnsers) or tupled names (just you get all names in the list above)...

    than my while loop must stop running... but it don't works...

    The problem is thad if you typ not the current names (you must be find in my list tuple),
    than stop it with running, even if you don't get all names (may be find in the tupple list)...

    As example you typ Bart (this name is not generated in this list tuple above)....., this
    script stop with running, but even you don't get all names typed, thad i get generated
    in my tuple list...

    This is just the problem... just please, can enyone help me to correct my code ?...
    so i can expiriment with it ?....

    Thanks for help, Jamie....
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2009
    Posts
    667
    Rep Power
    40
    The Python Style Guide says to use lower case letters and underscores for variable names https://www.python.org/dev/peps/pep-0008/
    Code:
    run = True
    
    hobbys = {'Jamie' : 'Natuurkunde',
            'Ellister' : 'Darten',
            'Sander' : 'Lezen',
            'John' : 'Muziek',
            'Rob' : 'Speelgoed'}
    
    while run:
    
        ## input is a string
        names = input('Typ een naam om zijn hobby te weten: ')
        print(names)
        if names in hobbys:
            print(hobbys[names])
            run=False

IMN logo majestic logo threadwatch logo seochat tools logo