1. Que variable se debe de declarar primero en el programa
2. Porque siempre debe de ir from SimPy.Simulation import * y es importante que lleve el comentario adelante.
3. Es necesario poner en el programa todos los componentes
4. Que significan las tres comillas o porque son importantes
5. Para qué sirve def generar(self, cantidad, interarribo):
6. Qué función tiene el for,yield,class,def y el print
Son todas mis dudas profesor
1. Respuesta
ResponderEliminardef __init__(self,seed=333):
se declara una semilla 333 para generar números al azar.
2. Respuesta
El principal programa es SimPy.Simulation. El comentario es para nosotros, se pueden escribir o no. El interprete de Python no lo lee.
3. Respuesta
No sé. Puedes borrar uno por uno, y ver si todavía da la misma respuesta o no. La mayoría de las componentes deben ser necesarios.
4. Respuesta
Las tres comillas dobles indican comentario. Es decir todo lo que esté dentro de esas comillas, no lo ejecuta Python; se ponen ahí para que entendamos el programa mejor, son notas para nosotros.
5. Respuesta
def generate(self,number,interval):
es parte de la clase:
class Source(Process):
Genera a los clientes. self es una palabra clave de SimPy, que está escrito en inglés. self quiere decir propio. Las otras variables están en español. Están definidos aquí.
6. Respuesta
for i in range(number):
for es palabra clave, el programa Python lo interpreta como la repetición, en este caso de i en el rango range(number)
yield hold,self,t
yield es palabra clave, Python lo interpreta la clase:
De los documentos de Python, tenemos:
help> yield
The ``yield`` statement
***********************
yield_stmt ::= yield_expression
The ``yield`` statement is only used when defining a generator
function, and is only used in the body of the generator function.
Using a ``yield`` statement in a function definition is sufficient to
cause that definition to create a generator function instead of a
normal function. When a generator function is called, it returns an
iterator known as a generator iterator, or more commonly, a generator.
The body of the generator function is executed by calling the
``next()`` function on the generator repeatedly until it raises an
exception.
When a ``yield`` statement is executed, the state of the generator is
frozen and the value of **expression_list** is returned to
``next()``'s caller. By "frozen" we mean that all local state is
retained, including the current bindings of local variables, the
instruction pointer, and the internal evaluation stack: enough
information is saved so that the next time ``next()`` is invoked, the
function can proceed exactly as if the ``yield`` statement were just
another external call.
The ``yield`` statement is allowed in the ``try`` clause of a ``try``
... ``finally`` construct. If the generator is not resumed before it
is finalized (by reaching a zero reference count or by being garbage
collected), the generator-iterator's ``close()`` method will be
called, allowing any pending ``finally`` clauses to execute.
See also:
**PEP 0255** - Simple Generators
The proposal for adding generators and the ``yield`` statement
to Python.
**PEP 0342** - Coroutines via Enhanced Generators
The proposal that, among other generator enhancements, proposed
allowing ``yield`` to appear inside a ``try`` ... ``finally``
block.
help>
class
Es otra palabra clave, y define el principio de la clase. Recuerda que Python es un lenguaje orientada a objetos. Estos lenguajes tienen clases, y los objectos dentro de las clases heredan propiedades de la clase.
def
Es una palabra clave, se usa para definiciones.
Finalmente print es una función.
print ("Average wait for %4d was %6.2f")% result
significa imprime, o escribe. Escribe lo que está dentro del paréntesis. Usa la sintaxis del lenguaje C, que inventó Dennis Ritchie, que acaba de morir. %4d es un entero, %6.2f es un número de punto flotante con dos dígitos después del punto.
Acordémonos de Dennis, mi ex compañero de trabajo, ahora que viene el Día de los Muertos.