I need help, please!

Hi, I’m doing a job with Python, I need help to do a school assignment, I’ve errors that I don’t know how to solve them, the program is as follows

def agregar_pasajero(turistas):
    nombre = raw_input("Ingrese nombre completo: ")
    dni = int(raw_input("Ingrese DNI: "))
    origen = raw-input("Ingrese el origen: ")

   
    for turista in turistas:
        if turista[1] == dni:
            print "El turista con DNI" ,dni, "ya esta registrado"
            return turistas

    
    turistas.append((nombre, dni, origen))
    return turistas


def agregar_ciudad(ciudades):
    origen = raw_input("Ingrese nombre de la ciudad: ")
    provincia = raw_input("Ingrese nombre de la provincia: ")

  
    for ciudad in ciudades:
        if ciudad[0] == origen:
            print "La ciudad",origen, "ya esta registrada"
            return ciudades

    
    ciudades.append((origen, provincia))
    return ciudades


def ver_ciudad(turistas):
    dni = int(raw_input("Ingrese DNI del pasajero: "))
    encontrado = False
    for turista in turistas:
        if turista[1] == dni:
            print "El pasajero viaja a la ciudad de", turista[2]
            encontrado = True
            break

    if encontrado is False:
        print "El pasajero no esta registrado"


def ver_cantidad_pasajeros_ciudad(turistas):
    contador = 0
    ciudad = raw_input("Ingrese nombre de la ciudad: ")
    for turista in turistas:
        if turista[2] == ciudad:
            contador += 1
    print "Viajan", contador, "a la ciudad de",ciudad


def ver_provincia(turistas):
    dni = int(raw_input("Ingrese DNI del pasajero: "))
    encontrado = False
    for turista in turistas:
        if turista[1] == dni:
            print "El pasajero viaja a la provincia de", turista[2]
            break

    if encontrado is False:
        print "El pasajero no esta registrado"


def ver_cantidad_pasajeros_provincia(turistas, ciudades):
    contador = 0
    provincia_usuario = raw_input("Ingrese nombre de la provincia: ")


    ciudades_provincia = []
    for ciudad, provincia in ciudades:
        if provincia_usuario == provincia:
            ciudades_provincia.append(ciudad)

    for turista in turistas:
        if turista[2] in ciudades_provincia:
            contador += 1
    print "Viajan", contador, "a la provincia de", provincia


def guardar(turistas, ciudades):
    print("Datos guardados")

    try:    
        with open('pasajeros.txt', 'a') as f:
            for nombre, dni, ciudad in turistas:
                f.write('{}\t{}\t{}\n'.format(nombre, dni, ciudad))

        with open('ciudades.txt', 'a') as f:
            for ciudad, provincia in ciudades:
                f.write('{}\t{}\n'.format(ciudad, provincia))
    except IOError:
        print("Error!")


def menu():
    print("1. Agregar pasajero")
    print("2. Agregar ciudad")
    print("3. Ver ciudad destino de un pasajero")
    print("4. Cantidad de pasajeros de una ciudad")
    print("5. Ver ciudad destino de un pasajero")
    print("6. Cantidad de pasajeros de una provincia")
    print("7. Salir")


def main():
    turistas = []
    ciudades = []

    opcion = 0
    while opcion != 7:
        menu()
        opcion = int(raw_input("Elige una opcion: "))

        if opcion == 1:
            turistas = agregar_pasajero(turistas)
        elif opcion == 2:
            ciudades = agregar_ciudad(ciudades)
        elif opcion == 3:
            ver_ciudad(turistas)
        elif opcion == 4:
            ver_cantidad_pasajeros_ciudad(turistas)
        elif opcion == 5:
            ver_provincia(turistas)
        elif opcion == 6:
            ver_cantidad_pasajeros_provincia(turistas, ciudades)
        elif opcion == 7:
            guardar(turistas, ciudades)
        else:
            print("Opcion incorrecta")


if __name__ == "__main__":
	main()

and the error is this:

Traceback (most recent call last):
  File "ara.py", line 139, in <module>
    main()
  File "ara.py", line 121, in main
    turistas = agregar_pasajero(turistas)
  File "ara.py", line 8, in agregar_pasajero
    origen = raw-input("Ingrese el origen: ")
NameError: global name 'raw' is not defined

It lets me choose option 1, enter name, ID, and the error comes up

(has functions in Spanish)

1 Like

@Araceli Welcome to the forum.

I see that you have written raw-input("Ingrese el origen: ") instead of writing raw_input(“Ingrese el origen:”)`. You need to replace the hyphen with an underscore.

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

It’s my first time posting on the forum, thank you very much for your help!!

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.