100% de satisfacción garantizada Inmediatamente disponible después del pago Tanto en línea como en PDF No estas atado a nada 4.2 TrustPilot
logo-home
Notas de lectura

Chapter 4 - Starting Out With Python Notes w/ Examples

Puntuación
-
Vendido
-
Páginas
6
Subido en
16-10-2024
Escrito en
2024/2025

Notes on chapter 4 of Tony Gaddis' Starting Out with Python complete with screenshotted examples of class lectures, both from the textbook and from the professor. Simplified bullet points.

Institución
Grado









Ups! No podemos cargar tu documento ahora. Inténtalo de nuevo o contacta con soporte.

Libro relacionado

Escuela, estudio y materia

Institución
Grado

Información del documento

Subido en
16 de octubre de 2024
Número de páginas
6
Escrito en
2024/2025
Tipo
Notas de lectura
Profesor(es)
Dr. reham abou-zaid
Contiene
Todas las clases

Temas

Vista previa del contenido

4.1: Introduction to Repetition Structures
● A repetition structure causes a statement or set of statements to execute repeatedly
● A condition-controlled loop uses a true/false condition to control the number of times that it
repeats
● A count-controlled loop repeats a specific number of times

4.2: The while Loop: A Condition-Controlled Loop
● While a condition is true, do some task
● Two parts: a condition is tested to be true or false, and a statement is executed if it is true
● while condition:
statement
statement
● If the statement is false, it exits the loop




● Each execution of the body of a loop is known as an iteration
The while Loop is a Pretest Loop
● The while loop is a pretest loop, meaning it tests the condition before performing an iteration
● Usually, you have to write some steps before the loop for it to iterate
Infinite Loops
● Almost always, loops must contain a way to terminate itself; something must make it false
eventually
● An infinite loop continues until the program is interrupted
● You should not write infinite loops; they are usually
mistakes

4.3: The for Loop: A Count-Controlled Loop
● Count-controlled loops iterate a specific number of times
● for variable in [value1, value2, etc…]
statement
statement

, ● The variable used in the for clause is the target variable
Using the range Function with the for Loop
● The range function creates an iterable
○ An iterable is an object similar to a list; it contains a sequence of values that can be
iterated over with something like a loop
● Instead of using a list of values, you can pass a number as an
argument
○ for num in range(5):
print(num)
○ This prints 5 numbers
○ Whatever number you put in the range, it goes from 0
to, but not including, that number
○ That code above is the same as:
for num in range[0, 1, 2, 3, 4]
print(num)
● If you pass 1 number as an argument, it acts as the end number with the starting number being 0;
if you pass 2 numbers, the first number is the starting number and the second is the end
● If you pass 1 or 2 numbers, each number increases by 1 in the range; if you pass 3, the 3rd
number acts as the interval (i.e. if you put 2, each number increases by 2); this is called the step
value




Using the Target Variable Inside the Loop
● Target variables reference each item in a sequence as the loop iterates
● Each time the loop iterates, the variable references the next number in the range
Letting the User Control Loop Iterations
● Sometimes, the user needs to decide how many loops need to be created
$7.99
Accede al documento completo:

100% de satisfacción garantizada
Inmediatamente disponible después del pago
Tanto en línea como en PDF
No estas atado a nada

Conoce al vendedor
Seller avatar
jaystoff

Conoce al vendedor

Seller avatar
jaystoff Eastern Illinois University
Seguir Necesitas iniciar sesión para seguir a otros usuarios o asignaturas
Vendido
0
Miembro desde
1 año
Número de seguidores
0
Documentos
1
Última venta
-

0.0

0 reseñas

5
0
4
0
3
0
2
0
1
0

Recientemente visto por ti

Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes