Python programming language provides the following types of loops to handle looping requirements:
1. While
2. Do While
3. For loop
Python provides three ways for executing the loops. While all the ways provide similar basic functionality, they differ in their syntax and condition-checking time.
Python uses indentation to define code blocks for decision making statements like if, elif and else. The if statement executes code if a condition is true, elif allows checking multiple conditions, and else runs code if all conditions are false. Loops like while and for repeat code, with while looping until a condition is false and for iterating over a sequence. Nested loops can run inner loops multiple times during outer loop iterations. The else block after a for runs if all iterations complete without breaking from the loop.
Looping Statements and Control Statements in PythonPriyankaC44
This document discusses looping statements and control statements in Python. It explains while loops, for loops, and the use of break, continue, else and pass statements. Some key points:
- While loops repeatedly execute statements as long as a condition is true. For loops iterate over a sequence.
- Break and continue statements can alter loop flow - break exits the entire loop, continue skips to the next iteration.
- The else block in loops runs when the condition becomes false (while) or the sequence is complete (for).
- Pass is a null operation used when syntax requires a statement but no operation is needed.
Several examples of loops and control statements are provided to demonstrate their usage.
The document discusses Python control structures including if-else statements, indentation, and loops. It provides examples of if statements, if-else statements, nested if statements, and elif statements to test conditions and execute code blocks accordingly. It also discusses for loops and the range() function to iterate through sequences and generate number sequences to repeat code. Loops simplify problems by allowing code to repeat without rewriting and help traverse data structures.
First in the series of slides for python programming, covering topics like programming language, python programming constructs, loops and control statements.
The document discusses different types of loops in Python including while loops, for loops, and infinite loops. It provides examples of using while loops to iterate until a condition is met, using for loops to iterate over a set of elements when the number of iterations is known, and how to terminate loops early using break or skip iterations using continue. It also discusses using the range() function to generate a sequence of numbers to iterate over in for loops.
C for Loop
Loops are used in programming to execute a block of code repeatedly until a specified condition is met. In this tutorial, you will learn to create for loop in C programming.
C programming has three types of loops:
for loop
while loop
do...while loop
Python programming language provides the following types of loops to handle looping requirements:
1. While
2. Do While
3. For loop
Python provides three ways for executing the loops. While all the ways provide similar basic functionality, they differ in their syntax and condition-checking time.
Python uses indentation to define code blocks for decision making statements like if, elif and else. The if statement executes code if a condition is true, elif allows checking multiple conditions, and else runs code if all conditions are false. Loops like while and for repeat code, with while looping until a condition is false and for iterating over a sequence. Nested loops can run inner loops multiple times during outer loop iterations. The else block after a for runs if all iterations complete without breaking from the loop.
Looping Statements and Control Statements in PythonPriyankaC44
This document discusses looping statements and control statements in Python. It explains while loops, for loops, and the use of break, continue, else and pass statements. Some key points:
- While loops repeatedly execute statements as long as a condition is true. For loops iterate over a sequence.
- Break and continue statements can alter loop flow - break exits the entire loop, continue skips to the next iteration.
- The else block in loops runs when the condition becomes false (while) or the sequence is complete (for).
- Pass is a null operation used when syntax requires a statement but no operation is needed.
Several examples of loops and control statements are provided to demonstrate their usage.
The document discusses Python control structures including if-else statements, indentation, and loops. It provides examples of if statements, if-else statements, nested if statements, and elif statements to test conditions and execute code blocks accordingly. It also discusses for loops and the range() function to iterate through sequences and generate number sequences to repeat code. Loops simplify problems by allowing code to repeat without rewriting and help traverse data structures.
First in the series of slides for python programming, covering topics like programming language, python programming constructs, loops and control statements.
The document discusses different types of loops in Python including while loops, for loops, and infinite loops. It provides examples of using while loops to iterate until a condition is met, using for loops to iterate over a set of elements when the number of iterations is known, and how to terminate loops early using break or skip iterations using continue. It also discusses using the range() function to generate a sequence of numbers to iterate over in for loops.
C for Loop
Loops are used in programming to execute a block of code repeatedly until a specified condition is met. In this tutorial, you will learn to create for loop in C programming.
C programming has three types of loops:
for loop
while loop
do...while loop
what are loop in general
what is loop in c language
uses of loop in c language
types of loop in c language
program of loop in c language
syantax of loop in c language
The document discusses different types of iteration statements in Python including while loops, for loops, and nested loops. While loops execute a block of statements repeatedly until a condition is False. For loops iterate over a sequence, assigning each element to a variable to execute the block. Nested loops contain one loop within another. Unconditional statements like break, continue, and pass can alter normal loop execution flow. Break exits the current loop, continue skips to the next iteration, and pass acts as a placeholder. The range() function generates arithmetic progressions for iterating over sequences of numbers.
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested LoopPriyom Majumder
This file is based on the loops that could be used in C Programming. These are explained with some examples and sample programmings and screen shots.
NOTE: The software used in this programming is Notepad++ and the programs are compiled and run through gcc compiler using command prompt.
Operators and expressions are fundamental concepts in Python programming. The document discusses various types of operators used to manipulate operands, including arithmetic, comparison, assignment, logical, bitwise, and membership operators. It also covers expressions, which are combinations of operators and operands that evaluate to a value. Several types of expressions are described, such as constant, arithmetic, integral, floating, relational, logical, bitwise, and combinational expressions. Control flow statements like if, if-else, if-elif-else are also covered, along with looping using for and while loops and the break, continue, and pass statements.
This document provides an introduction to the C programming language. It explains that C allows programmers to write code using functions and keywords rather than billions of 1s and 0s. It then discusses some basic C concepts like #include, main(), printf(), variables, data types, if/else statements, for loops, and functions. The document is meant to explain the basic building blocks of a C program to a beginner reader.
This document discusses various loop constructs in C programming including while, do-while, for, and exiting loops. It covers:
- The while loop evaluates its controlling expression first before executing the loop body.
- The do-while loop evaluates its controlling expression after executing the loop body, so the body is always executed at least once.
- The for loop is ideal for loops with a counting variable, allowing initialization, a controlling expression, and an increment/decrement expression to be specified.
- break exits the entire loop, continue skips to the next iteration, and goto allows jumping to any statement but is rarely needed and can harm readability.
Python is a general purpose programming language that can be used for both programming and scripting. It is an interpreted language, meaning code is executed line by line by the Python interpreter. Python code is written in plain text files with a .py extension. Key features of Python include being object-oriented, using indentation for code blocks rather than brackets, and having a large standard library. Python code can be used for tasks like system scripting, web development, data analysis, and more.
The document discusses while loops in programming. It defines a while loop as a structure that executes a sequence of instructions multiple times. It explains that while loops are used when the number of repetitions is unknown and cannot be calculated in advance. The document provides examples of using while loops with loop counters to run code a specific number of times and examples of infinite loops. It also discusses using the break statement to exit a loop early.
There are two main types of loops in C - entry control loops and exit control loops. Entry control loops like for and while loops check the loop condition at entry, while exit control loops like do-while check the condition at exit. For loops use initialization, condition, and update statements. While loops continuously check a condition. Do-while loops execute the body at least once before checking the condition. Loops can be nested, with one loop inside another. This allows looping of statements within another loop.
The document provides examples and explanations of different control structures like loops (while, do-while, for) and increment/decrement operators in C programming. It includes the syntax and working of each loop type along with examples to calculate sum of numbers, find average of scores, and print patterns using nested loops. Increment and decrement operators are demonstrated with examples showing the order of evaluation.
Learn python in easy steps. This presentation will cover followings
1. Python basics
2. How to write a python code
3. Variable usage & their syntax
4. Strings handling
5. Files handling
6. How to use loops and others.
7. Python Vs C language.
This document discusses decision making and loops in Python. It begins with an introduction to decision making using if/else statements and examples of checking conditions. It then covers different types of loops - for, while, and do-while loops. The for loop is used when the number of iterations is known, while the while loop is used when it is unknown. It provides examples of using range() with for loops and examples of while loops.
Python Session - 4
if
nested-if
if-else
elif (else if)
for loop (for iterating_var in sequence: )
while loop
break
continnue
pass
What is a function in Python?
Types of Functions
How to Define & Call Function
Scope and Lifetime of variables
lambda functions(anonymous functions)
The document discusses different types of nested loops in programming. It explains nested while loops, do-while loops, and nested for loops. For nested while loops, the inner loop must start after the outer loop and end before the outer loop. An example prints a series using nested while loops. Do-while loops execute the loop statement once before checking the condition. An example uses do-while to check if a number is positive or negative. Nested for loops can contain another for loop in its body, as long as the inner loop variable has a different name. An example prints a series using nested for loops.
Helpmeinhomework Experts provides the most trusted and reliable online Programming assignment help . Programming is one of the most widely taught subjects across the universities. The complexity of subjects make students seek for quality and affordable online guidance. We at helpmeinhomework.com Experts cater to such needs of the students. Our programming experts provide assignment help to students across UK, USA and Australia for multiple programming languages i.e. Java, Python, HTML, PHP, Assembly language, C ,Linux ,Unix etc.
The document provides information on various decision making and looping constructs in Python like if, else, elif, for, while loops. It explains the syntax and usage of these statements with examples. Key decision making constructs covered include if-else, if-elif-else statements. Looping constructs covered include for loops over sequences, range function to generate sequences, while loops, break and continue keywords in loops. Nested if statements and usage of else block with for and while loops are also discussed.
This document discusses different types of loops in Python including definite loops using for statements, indefinite loops using while statements, and different patterns for indefinite loops like interactive loops, sentinel loops, and end-of-file loops. It provides examples of using accumulators and loop variables to iterate over a sequence of user-entered numbers and calculate the average. Key loop concepts like pre-test loops, priming reads, and avoiding infinite loops are also covered.
Complete Course Available at: https://github.com/Ebad8931/PythonWorkshop
Basic Concepts of Loops and Conditional Statements in Python are introduced in the presentation. Also covers How to get input from the Console and includes interactive Problems.
The document discusses three types of jumping statements in C language: break, continue, and goto.
1) The break statement terminates the nearest enclosing loop or switch statement and transfers execution to the statement following the terminated statement.
2) The continue statement skips the rest of the current loop iteration and transfers control to the loop check.
3) The goto statement unconditionally transfers control to the labeled statement. It is useful for branching within nested loops when a break statement cannot exit properly.
The document summarizes common repetition structures in C programming including while, do-while, for loops as well as break, continue, and exit statements. It explains that repetition structures allow code to execute repeatedly while a condition is true and covers the syntax and usage of each structure.
Build the Next Generation of Apps with the Einstein 1 Platform.
Rejoignez Philippe Ozil pour une session de workshops qui vous guidera à travers les détails de la plateforme Einstein 1, l'importance des données pour la création d'applications d'intelligence artificielle et les différents outils et technologies que Salesforce propose pour vous apporter tous les bénéfices de l'IA.
Digital Twins Computer Networking Paper Presentation.pptxaryanpankaj78
A Digital Twin in computer networking is a virtual representation of a physical network, used to simulate, analyze, and optimize network performance and reliability. It leverages real-time data to enhance network management, predict issues, and improve decision-making processes.
More Related Content
Similar to While_for_loop presententationin first year students
what are loop in general
what is loop in c language
uses of loop in c language
types of loop in c language
program of loop in c language
syantax of loop in c language
The document discusses different types of iteration statements in Python including while loops, for loops, and nested loops. While loops execute a block of statements repeatedly until a condition is False. For loops iterate over a sequence, assigning each element to a variable to execute the block. Nested loops contain one loop within another. Unconditional statements like break, continue, and pass can alter normal loop execution flow. Break exits the current loop, continue skips to the next iteration, and pass acts as a placeholder. The range() function generates arithmetic progressions for iterating over sequences of numbers.
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested LoopPriyom Majumder
This file is based on the loops that could be used in C Programming. These are explained with some examples and sample programmings and screen shots.
NOTE: The software used in this programming is Notepad++ and the programs are compiled and run through gcc compiler using command prompt.
Operators and expressions are fundamental concepts in Python programming. The document discusses various types of operators used to manipulate operands, including arithmetic, comparison, assignment, logical, bitwise, and membership operators. It also covers expressions, which are combinations of operators and operands that evaluate to a value. Several types of expressions are described, such as constant, arithmetic, integral, floating, relational, logical, bitwise, and combinational expressions. Control flow statements like if, if-else, if-elif-else are also covered, along with looping using for and while loops and the break, continue, and pass statements.
This document provides an introduction to the C programming language. It explains that C allows programmers to write code using functions and keywords rather than billions of 1s and 0s. It then discusses some basic C concepts like #include, main(), printf(), variables, data types, if/else statements, for loops, and functions. The document is meant to explain the basic building blocks of a C program to a beginner reader.
This document discusses various loop constructs in C programming including while, do-while, for, and exiting loops. It covers:
- The while loop evaluates its controlling expression first before executing the loop body.
- The do-while loop evaluates its controlling expression after executing the loop body, so the body is always executed at least once.
- The for loop is ideal for loops with a counting variable, allowing initialization, a controlling expression, and an increment/decrement expression to be specified.
- break exits the entire loop, continue skips to the next iteration, and goto allows jumping to any statement but is rarely needed and can harm readability.
Python is a general purpose programming language that can be used for both programming and scripting. It is an interpreted language, meaning code is executed line by line by the Python interpreter. Python code is written in plain text files with a .py extension. Key features of Python include being object-oriented, using indentation for code blocks rather than brackets, and having a large standard library. Python code can be used for tasks like system scripting, web development, data analysis, and more.
The document discusses while loops in programming. It defines a while loop as a structure that executes a sequence of instructions multiple times. It explains that while loops are used when the number of repetitions is unknown and cannot be calculated in advance. The document provides examples of using while loops with loop counters to run code a specific number of times and examples of infinite loops. It also discusses using the break statement to exit a loop early.
There are two main types of loops in C - entry control loops and exit control loops. Entry control loops like for and while loops check the loop condition at entry, while exit control loops like do-while check the condition at exit. For loops use initialization, condition, and update statements. While loops continuously check a condition. Do-while loops execute the body at least once before checking the condition. Loops can be nested, with one loop inside another. This allows looping of statements within another loop.
The document provides examples and explanations of different control structures like loops (while, do-while, for) and increment/decrement operators in C programming. It includes the syntax and working of each loop type along with examples to calculate sum of numbers, find average of scores, and print patterns using nested loops. Increment and decrement operators are demonstrated with examples showing the order of evaluation.
Learn python in easy steps. This presentation will cover followings
1. Python basics
2. How to write a python code
3. Variable usage & their syntax
4. Strings handling
5. Files handling
6. How to use loops and others.
7. Python Vs C language.
This document discusses decision making and loops in Python. It begins with an introduction to decision making using if/else statements and examples of checking conditions. It then covers different types of loops - for, while, and do-while loops. The for loop is used when the number of iterations is known, while the while loop is used when it is unknown. It provides examples of using range() with for loops and examples of while loops.
Python Session - 4
if
nested-if
if-else
elif (else if)
for loop (for iterating_var in sequence: )
while loop
break
continnue
pass
What is a function in Python?
Types of Functions
How to Define & Call Function
Scope and Lifetime of variables
lambda functions(anonymous functions)
The document discusses different types of nested loops in programming. It explains nested while loops, do-while loops, and nested for loops. For nested while loops, the inner loop must start after the outer loop and end before the outer loop. An example prints a series using nested while loops. Do-while loops execute the loop statement once before checking the condition. An example uses do-while to check if a number is positive or negative. Nested for loops can contain another for loop in its body, as long as the inner loop variable has a different name. An example prints a series using nested for loops.
Helpmeinhomework Experts provides the most trusted and reliable online Programming assignment help . Programming is one of the most widely taught subjects across the universities. The complexity of subjects make students seek for quality and affordable online guidance. We at helpmeinhomework.com Experts cater to such needs of the students. Our programming experts provide assignment help to students across UK, USA and Australia for multiple programming languages i.e. Java, Python, HTML, PHP, Assembly language, C ,Linux ,Unix etc.
The document provides information on various decision making and looping constructs in Python like if, else, elif, for, while loops. It explains the syntax and usage of these statements with examples. Key decision making constructs covered include if-else, if-elif-else statements. Looping constructs covered include for loops over sequences, range function to generate sequences, while loops, break and continue keywords in loops. Nested if statements and usage of else block with for and while loops are also discussed.
This document discusses different types of loops in Python including definite loops using for statements, indefinite loops using while statements, and different patterns for indefinite loops like interactive loops, sentinel loops, and end-of-file loops. It provides examples of using accumulators and loop variables to iterate over a sequence of user-entered numbers and calculate the average. Key loop concepts like pre-test loops, priming reads, and avoiding infinite loops are also covered.
Complete Course Available at: https://github.com/Ebad8931/PythonWorkshop
Basic Concepts of Loops and Conditional Statements in Python are introduced in the presentation. Also covers How to get input from the Console and includes interactive Problems.
The document discusses three types of jumping statements in C language: break, continue, and goto.
1) The break statement terminates the nearest enclosing loop or switch statement and transfers execution to the statement following the terminated statement.
2) The continue statement skips the rest of the current loop iteration and transfers control to the loop check.
3) The goto statement unconditionally transfers control to the labeled statement. It is useful for branching within nested loops when a break statement cannot exit properly.
The document summarizes common repetition structures in C programming including while, do-while, for loops as well as break, continue, and exit statements. It explains that repetition structures allow code to execute repeatedly while a condition is true and covers the syntax and usage of each structure.
Similar to While_for_loop presententationin first year students (20)
Build the Next Generation of Apps with the Einstein 1 Platform.
Rejoignez Philippe Ozil pour une session de workshops qui vous guidera à travers les détails de la plateforme Einstein 1, l'importance des données pour la création d'applications d'intelligence artificielle et les différents outils et technologies que Salesforce propose pour vous apporter tous les bénéfices de l'IA.
Digital Twins Computer Networking Paper Presentation.pptxaryanpankaj78
A Digital Twin in computer networking is a virtual representation of a physical network, used to simulate, analyze, and optimize network performance and reliability. It leverages real-time data to enhance network management, predict issues, and improve decision-making processes.
Supermarket Management System Project Report.pdfKamal Acharya
Supermarket management is a stand-alone J2EE using Eclipse Juno program.
This project contains all the necessary required information about maintaining
the supermarket billing system.
The core idea of this project to minimize the paper work and centralize the
data. Here all the communication is taken in secure manner. That is, in this
application the information will be stored in client itself. For further security the
data base is stored in the back-end oracle and so no intruders can access it.
A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...DharmaBanothu
The Network on Chip (NoC) has emerged as an effective
solution for intercommunication infrastructure within System on
Chip (SoC) designs, overcoming the limitations of traditional
methods that face significant bottlenecks. However, the complexity
of NoC design presents numerous challenges related to
performance metrics such as scalability, latency, power
consumption, and signal integrity. This project addresses the
issues within the router's memory unit and proposes an enhanced
memory structure. To achieve efficient data transfer, FIFO buffers
are implemented in distributed RAM and virtual channels for
FPGA-based NoC. The project introduces advanced FIFO-based
memory units within the NoC router, assessing their performance
in a Bi-directional NoC (Bi-NoC) configuration. The primary
objective is to reduce the router's workload while enhancing the
FIFO internal structure. To further improve data transfer speed,
a Bi-NoC with a self-configurable intercommunication channel is
suggested. Simulation and synthesis results demonstrate
guaranteed throughput, predictable latency, and equitable
network access, showing significant improvement over previous
designs
AI in customer support Use cases solutions development and implementation.pdfmahaffeycheryld
AI in customer support will integrate with emerging technologies such as augmented reality (AR) and virtual reality (VR) to enhance service delivery. AR-enabled smart glasses or VR environments will provide immersive support experiences, allowing customers to visualize solutions, receive step-by-step guidance, and interact with virtual support agents in real-time. These technologies will bridge the gap between physical and digital experiences, offering innovative ways to resolve issues, demonstrate products, and deliver personalized training and support.
https://www.leewayhertz.com/ai-in-customer-support/#How-does-AI-work-in-customer-support
Levelised Cost of Hydrogen (LCOH) Calculator ManualMassimo Talia
The aim of this manual is to explain the
methodology behind the Levelized Cost of
Hydrogen (LCOH) calculator. Moreover, this
manual also demonstrates how the calculator
can be used for estimating the expenses associated with hydrogen production in Europe
using low-temperature electrolysis considering different sources of electricity
We have designed & manufacture the Lubi Valves LBF series type of Butterfly Valves for General Utility Water applications as well as for HVAC applications.
Open Channel Flow: fluid flow with a free surfaceIndrajeet sahu
Open Channel Flow: This topic focuses on fluid flow with a free surface, such as in rivers, canals, and drainage ditches. Key concepts include the classification of flow types (steady vs. unsteady, uniform vs. non-uniform), hydraulic radius, flow resistance, Manning's equation, critical flow conditions, and energy and momentum principles. It also covers flow measurement techniques, gradually varied flow analysis, and the design of open channels. Understanding these principles is vital for effective water resource management and engineering applications.
Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...Transcat
Join us for this solutions-based webinar on the tools and techniques for commissioning and maintaining PV Systems. In this session, we'll review the process of building and maintaining a solar array, starting with installation and commissioning, then reviewing operations and maintenance of the system. This course will review insulation resistance testing, I-V curve testing, earth-bond continuity, ground resistance testing, performance tests, visual inspections, ground and arc fault testing procedures, and power quality analysis.
Fluke Solar Application Specialist Will White is presenting on this engaging topic:
Will has worked in the renewable energy industry since 2005, first as an installer for a small east coast solar integrator before adding sales, design, and project management to his skillset. In 2022, Will joined Fluke as a solar application specialist, where he supports their renewable energy testing equipment like IV-curve tracers, electrical meters, and thermal imaging cameras. Experienced in wind power, solar thermal, energy storage, and all scales of PV, Will has primarily focused on residential and small commercial systems. He is passionate about implementing high-quality, code-compliant installation techniques.
2. Outline
1. For loop
2. Range function
3. Break, continue, and Pass
statement
4. Booleans
5. While loop
6. Nested loop
3. For Loop
The for loop in python iterates over the items of any sequence
be it a list or a string. Moreover, using for loop in the program
will minimize the line of code.
Points to keep in mind while using for loop in python:
➔ It should always start with for keyword and should
end with a colon(:).
➔ The statements inside the loop should be
indented(four spacebars).
Syntax:
For iterator_variable in sequence:
statement(s)
4. Example
Code:
for i in range(6):
print(“Hello World!”)
Output:
print(“Hello World!”)
print(“Hello World!”)
print(“Hello World!”)
print(“Hello World!”)
print(“Hello World!”)
This is actually a temporary
variable which store the
number of iteration
Number of times you want to
execute the statement
5. Range function
To iterate over a sequence of numbers, the built-in function
range() comes in handy. It generates arithmetic
progressions. For example, if we want to print a whole number
from 0 to 10, it can be done using a range(11) function in a for
loop.
In a range() function we can also define an optional start and
the endpoint to the sequence. The start is always included
while the endpoint is always excluded.
Example:
for i in range(1, 6):
print("Hello World!")
Output: Prints Hello World! five times
Starting point
Ending point
6. Range function
The range() function also takes in another optional
parameter i.e. step size. Passing step size in a range()
function is important when you want to print the value
uniformly with a certain interval.
Step size is always passed as a third parameter where the
first parameter is the starting point and the second
parameter is the ending point. And if the step_size is not
provided it will take 1 as a default step_size.
Example:
for i in range(0,20, 2):
print(i)
Output: prints all the even numbers till 20
Step size
cont….
7. Sum of numbers
-Write a program to find the sum of all the numbers less than
a number entered by the user. Display the sum.
Expected Output:
1
8. Break, Continue, & Pass Statement
(Loop control statement)
➔ A break statement is used to immediately terminate a
loop.
➔ A continue statement is used to skip out future
commands inside a loop and return to the top of the
loop.
➔ A Pass is a null operation — when it is executed,
nothing happens. It is useful as a placeholder when a
statement is required syntactically when no code
needs to be executed.
➔ These statements can be used with for or while loops.
9. Break, Continue, & Pass Statement (Loop control statement)
Example:
for i in range(10):
if i == 3:
break
print(i)
Output:
0
1
2
Break
for i in range(5):
if i == 3:
continue
print(i)
Output:
0
1
2
4
Continue
for i in range(10):
Pass
Output:
Nothing will be printed
Pass
10. Magic Number
Write a program that makes the user guess a particular
number between 1 and 100. Save the number to be
guessed in a variable called magic_number.
If the user guesses a number higher than the secret
number, you should say Too high!. Similarly, you should
say Too low! if they guess a number lower than the secret
number. Once they guess the number, say Correct!
Expected Output:
2
11. Boolean
A boolean is a value that can be either True or False.
Example:
brought_food = True
brought_drink = False
- Boolean variables don't have quotation marks.
- The values must start with capital letters.
12. While Loop
➔ while loop repeatedly carries out a target statement while the condition is
true. The loop iterates as long as the defined condition is True.
➔ When the condition becomes false, program control passes to the line
immediately following the loop.
Example:
while True:
print("I am a programmer")
break
while False:
print("Not printed because while the condition is already False")
break
Output:
I am a programmer
13. While Loop
Example:
x = 1
while x > 0:
print ("Hello!")
x = x - 1
print ("I like Python.")
Output:
Hello!
I like Python.
14. Guess the number
Write a program where the user enters a number.
If the number matches the number, acknowledge
the user and stop the program. If the number
does not match, keep asking for the next number.
Expected Output:
3
15. Nested Loop
Loop within a loop is called a nested loop.
➔ For loop within for loop is called a nested for loop.
➔ While loop within while loop is called as nested while
loop.
for i in range(4):
for j in range(3):
print ("Hello!")
Example: Nested for loop
i = 1
j = 5
while i < 4:
while j < 8:
print(i,",", j)
j = j + 1 j
i = i + 1
Example: Nested while loop
16. Nested Loop(Example)
for i in range(4):
x = 5
while x > 1:
print (x)
x = x - 1
Output:
5
4
3
2
5
4
3
2
5
4
3
2
5
4
3
2
17. Rolling a dice
Write a program that will print out all combinations that can
be made when 2 dice are rolled. And should continue until all
values up to 6, and 6 are printed. (Hint: You should have a
space after each comma!)
Expected Output:
4