vendredi 11 juin 2021

How to set an if-else statement based on whether value is a string

I'm trying to set up an if-else statement where if the variable code isn't a string then 'Invalid' would print, otherwise if variables x, y and z are set as 'Undefined' 'Not found' would print else the variable values would print. Below is the code I've attempted, but only 'Invalid is being output.

code = get_code(serial_number, type)
    if code != str:
        print('Invalid')
    else:
        x = compute_x(code)
        y = compute_y(code)
        z = compute_z(code)
        if x or y or z == 'Undetermined':
            print('Not found')
        else: 
            print('{} {} {}'.format(x, y, z,))
    return

Aucun commentaire:

Enregistrer un commentaire