SlideShare a Scribd company logo
Welcome
Comments
Comments are useful information that the developers
provide to make the reader understand the source code. It
explains the logic or a part of it used in the code. There are
two types of comment in Python:
● Single line comments: Python single line comment starts
with hashtag symbol with no white spaces.
Multi-line string as comment: Python multi-line comment
is a piece of text enclosed in a delimiter (“””) on each end
of the comment.
Headline
Subtitle
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum gravida
placerat dictum. Sed sagittis accumsan dolor ut malesuada. Duis sit amet
placerat quam. Donec eget eros egestas nunc venenatis suscipit at at felis. Duis
sit amet placerat quam.
● Deleting/Updating from a String –
● In Python, Updation or deletion of characters from a String is not allowed
because Strings are immutable. Only new strings can be reassigned to the
same name.
Mutability and Immutability
Basics of Input/Output
Input() and print()
name = input('What is your name?n') # n ---> newline ---> It causes a line
break
print(name)
When input() function executes program flow will be stopped until the user has given input.
The text or message displayed on the output screen to ask a user to enter an input value is optional
i.e. the prompt, which will be printed on the screen is optional.
Whatever you enter as input, the input function converts it into a string. if you enter an integer value
still input() function converts it into a string. You need to explicitly convert it into an integer in your
code using typecasting.
# Program to check input
# type in Python
num = input ("Enter number :")
print(num)
name1 = input("Enter name : ")
print(name1)
# Printing type of input value
print ("type of number", type(num))
print ("type of name", type(name1))
It will show the type of input as str
num = int(input("Enter a number: "))
print(num, " ", type(num))
floatNum = float(input("Enter a decimal number: "))
print(floatNum, " ", type(floatNum))
what will it show about the type of input?
# Python Program for
# Creation of String
# String with single quotes
print('Welcome to the GDSC HIT')
# String with double quotes
print("I'm a Abhishek Pandey")
# String with triple quotes
print(‘ ‘ ‘ I'm a 3rd year student and I live in a world of “Aliens“ ‘ ‘ ‘ )
# Python Program to Access
# characters of String
String1 = “Python“
# Printing First character
print(String1[0])
# Printing Last character
print(String1[-1])
In computer programming, we use the if statement to run a block code only
when a certain condition is met.
Indentation in Python
Indentation is a very important concept of Python because
without properly indenting the Python code, you will end
up seeing IndentationError and the code will not get
compiled.
Python indentation refers to adding white space before a
statement to a particular block of code. In another word,
all the statements with the same space to the right,
belong to the same code block
If Elif Else
Let’s Create a Guessing
game:
Let’s try to implement the following condition
For example, assigning grades (A, B, C) based on marks obtained by a student.
1.if the percentage is above 90, assign grade A
2.if the percentage is above 75, assign grade B
3.if the percentage is above 65, assign grade C
Colors, Charts, and Icons
While Loop in Python:-
In python, a while loop is used to execute a block of statements repeatedly until a given condition is satisfied.
And when the condition becomes false, the line immediately after the loop in the program is executed.
# Python program to illustrate while loop
count = 0
while (count < 3):
count = count + 1
print("Hello!")
Examples of While Loop with else statement
# Python program to illustrate
# combining else with while
count = 0
while (count < 3):
count = count + 1
print("Hello")
else:
print("In Else Block")
Colors, Charts, and Icons
For Loop in Python:-
For loops are used for sequential traversal. For example: traversing a list or string or array etc. In Python, there
is “for in” loop which is similar to for each loop in other languages. Let us learn how to use for in loop for
sequential traversals.
# Python program to illustrate
# Iterating over range 0 to n-1
n = 4
for i in range(0, n):
print(i)
output?
Decrementing With range():
for i in range(10, -6, -2):
print(i)
This will start at 10 and count down by 2 until you reach -6, or rather -4 because you don’t include -6.
This will start at 10 and count down by 2 until you reach -6, or rather -4 because you don’t include -6.
Colors, Charts, and Icons
Nested Loops:-
Python programming language allows to use one loop inside another loop.
We will use nested loop to print right angle triangle star pattern.
Let’s see how this work:
for i in range(1, 5):
for j in range(i):
print(i, end=' ')
print()
what is end here?
# ends the output with a space
print("Welcome to", end = ' ')
print("GeeksforGeeks", end= ' ')
Print statement automatically print a new line after the prompt inside it.
To prevent creating new line and to continue with same line we use end=“ ”
Star Patterns:-
Example:
for i in range(1, 9):
for j in range(i):
print(“*”, end=' ')
print()
Python Print Star Patterns 14 Programs
https://easycodebook.com/2021/05/python-print-star-pattern-shapes-programs/
Thank You 

More Related Content

Similar to gdscpython.pdf

Unit2 input output
Unit2 input outputUnit2 input output
Unit2 input output
deepak kumbhar
 
Python-01| Fundamentals
Python-01| FundamentalsPython-01| Fundamentals
Python-01| Fundamentals
Mohd Sajjad
 
Control structures pyhton
Control structures  pyhtonControl structures  pyhton
Control structures pyhton
Prakash Jayaraman
 
MODULE. .pptx
MODULE.                              .pptxMODULE.                              .pptx
MODULE. .pptx
Alpha337901
 
Advanced Web Technology ass.pdf
Advanced Web Technology ass.pdfAdvanced Web Technology ass.pdf
Advanced Web Technology ass.pdf
simenehanmut
 
Notes1
Notes1Notes1
Notes1hccit
 
Python fundamentals
Python fundamentalsPython fundamentals
Python fundamentals
natnaelmamuye
 
Python.pptx
Python.pptxPython.pptx
Python.pptx
EliasPetros
 
python
pythonpython
python
ultragamer6
 
Python-Cheat-Sheet.pdf
Python-Cheat-Sheet.pdfPython-Cheat-Sheet.pdf
Python-Cheat-Sheet.pdf
Mohd Aves Malik
 
UNIT 4 python.pptx
UNIT 4 python.pptxUNIT 4 python.pptx
UNIT 4 python.pptx
TKSanthoshRao
 
Python Training in Chandigarh(Mohali)
Python Training in Chandigarh(Mohali)Python Training in Chandigarh(Mohali)
Python Training in Chandigarh(Mohali)
ExcellenceAcadmy
 
Python Training Course in Chandigarh(Mohali)
Python Training Course in Chandigarh(Mohali)Python Training Course in Chandigarh(Mohali)
Python Training Course in Chandigarh(Mohali)
ExcellenceAcadmy
 
Python for scientific computing
Python for scientific computingPython for scientific computing
Python for scientific computingGo Asgard
 
CBSE Class 12 Computer practical Python Programs and MYSQL
CBSE Class 12 Computer practical Python Programs and MYSQL CBSE Class 12 Computer practical Python Programs and MYSQL
CBSE Class 12 Computer practical Python Programs and MYSQL
Rishabh-Rawat
 
Python For Machine Learning
Python For Machine LearningPython For Machine Learning
Python For Machine Learning
YounesCharfaoui
 
Code In PythonFile 1 main.pyYou will implement two algorithms t.pdf
Code In PythonFile 1 main.pyYou will implement two algorithms t.pdfCode In PythonFile 1 main.pyYou will implement two algorithms t.pdf
Code In PythonFile 1 main.pyYou will implement two algorithms t.pdf
aishwaryaequipment
 
Python basics
Python basicsPython basics
Python basics
Manisha Gholve
 
chapter_5_ppt_em_220247.pptx
chapter_5_ppt_em_220247.pptxchapter_5_ppt_em_220247.pptx
chapter_5_ppt_em_220247.pptx
RAJAMURUGANAMECAPCSE
 
Lesson 03 python statement, indentation and comments
Lesson 03   python statement, indentation and commentsLesson 03   python statement, indentation and comments
Lesson 03 python statement, indentation and comments
Nilimesh Halder
 

Similar to gdscpython.pdf (20)

Unit2 input output
Unit2 input outputUnit2 input output
Unit2 input output
 
Python-01| Fundamentals
Python-01| FundamentalsPython-01| Fundamentals
Python-01| Fundamentals
 
Control structures pyhton
Control structures  pyhtonControl structures  pyhton
Control structures pyhton
 
MODULE. .pptx
MODULE.                              .pptxMODULE.                              .pptx
MODULE. .pptx
 
Advanced Web Technology ass.pdf
Advanced Web Technology ass.pdfAdvanced Web Technology ass.pdf
Advanced Web Technology ass.pdf
 
Notes1
Notes1Notes1
Notes1
 
Python fundamentals
Python fundamentalsPython fundamentals
Python fundamentals
 
Python.pptx
Python.pptxPython.pptx
Python.pptx
 
python
pythonpython
python
 
Python-Cheat-Sheet.pdf
Python-Cheat-Sheet.pdfPython-Cheat-Sheet.pdf
Python-Cheat-Sheet.pdf
 
UNIT 4 python.pptx
UNIT 4 python.pptxUNIT 4 python.pptx
UNIT 4 python.pptx
 
Python Training in Chandigarh(Mohali)
Python Training in Chandigarh(Mohali)Python Training in Chandigarh(Mohali)
Python Training in Chandigarh(Mohali)
 
Python Training Course in Chandigarh(Mohali)
Python Training Course in Chandigarh(Mohali)Python Training Course in Chandigarh(Mohali)
Python Training Course in Chandigarh(Mohali)
 
Python for scientific computing
Python for scientific computingPython for scientific computing
Python for scientific computing
 
CBSE Class 12 Computer practical Python Programs and MYSQL
CBSE Class 12 Computer practical Python Programs and MYSQL CBSE Class 12 Computer practical Python Programs and MYSQL
CBSE Class 12 Computer practical Python Programs and MYSQL
 
Python For Machine Learning
Python For Machine LearningPython For Machine Learning
Python For Machine Learning
 
Code In PythonFile 1 main.pyYou will implement two algorithms t.pdf
Code In PythonFile 1 main.pyYou will implement two algorithms t.pdfCode In PythonFile 1 main.pyYou will implement two algorithms t.pdf
Code In PythonFile 1 main.pyYou will implement two algorithms t.pdf
 
Python basics
Python basicsPython basics
Python basics
 
chapter_5_ppt_em_220247.pptx
chapter_5_ppt_em_220247.pptxchapter_5_ppt_em_220247.pptx
chapter_5_ppt_em_220247.pptx
 
Lesson 03 python statement, indentation and comments
Lesson 03   python statement, indentation and commentsLesson 03   python statement, indentation and comments
Lesson 03 python statement, indentation and comments
 

Recently uploaded

Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 

Recently uploaded (20)

Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 

gdscpython.pdf

  • 2.
  • 3.
  • 4. Comments Comments are useful information that the developers provide to make the reader understand the source code. It explains the logic or a part of it used in the code. There are two types of comment in Python: ● Single line comments: Python single line comment starts with hashtag symbol with no white spaces. Multi-line string as comment: Python multi-line comment is a piece of text enclosed in a delimiter (“””) on each end of the comment.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10. Headline Subtitle Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum gravida placerat dictum. Sed sagittis accumsan dolor ut malesuada. Duis sit amet placerat quam. Donec eget eros egestas nunc venenatis suscipit at at felis. Duis sit amet placerat quam.
  • 11. ● Deleting/Updating from a String – ● In Python, Updation or deletion of characters from a String is not allowed because Strings are immutable. Only new strings can be reassigned to the same name.
  • 13.
  • 14. Basics of Input/Output Input() and print() name = input('What is your name?n') # n ---> newline ---> It causes a line break print(name) When input() function executes program flow will be stopped until the user has given input. The text or message displayed on the output screen to ask a user to enter an input value is optional i.e. the prompt, which will be printed on the screen is optional. Whatever you enter as input, the input function converts it into a string. if you enter an integer value still input() function converts it into a string. You need to explicitly convert it into an integer in your code using typecasting.
  • 15. # Program to check input # type in Python num = input ("Enter number :") print(num) name1 = input("Enter name : ") print(name1) # Printing type of input value print ("type of number", type(num)) print ("type of name", type(name1)) It will show the type of input as str
  • 16. num = int(input("Enter a number: ")) print(num, " ", type(num)) floatNum = float(input("Enter a decimal number: ")) print(floatNum, " ", type(floatNum)) what will it show about the type of input?
  • 17. # Python Program for # Creation of String # String with single quotes print('Welcome to the GDSC HIT') # String with double quotes print("I'm a Abhishek Pandey") # String with triple quotes print(‘ ‘ ‘ I'm a 3rd year student and I live in a world of “Aliens“ ‘ ‘ ‘ )
  • 18. # Python Program to Access # characters of String String1 = “Python“ # Printing First character print(String1[0]) # Printing Last character print(String1[-1])
  • 19.
  • 20. In computer programming, we use the if statement to run a block code only when a certain condition is met. Indentation in Python Indentation is a very important concept of Python because without properly indenting the Python code, you will end up seeing IndentationError and the code will not get compiled. Python indentation refers to adding white space before a statement to a particular block of code. In another word, all the statements with the same space to the right, belong to the same code block If Elif Else
  • 21. Let’s Create a Guessing game:
  • 22. Let’s try to implement the following condition For example, assigning grades (A, B, C) based on marks obtained by a student. 1.if the percentage is above 90, assign grade A 2.if the percentage is above 75, assign grade B 3.if the percentage is above 65, assign grade C
  • 23. Colors, Charts, and Icons While Loop in Python:- In python, a while loop is used to execute a block of statements repeatedly until a given condition is satisfied. And when the condition becomes false, the line immediately after the loop in the program is executed. # Python program to illustrate while loop count = 0 while (count < 3): count = count + 1 print("Hello!") Examples of While Loop with else statement # Python program to illustrate # combining else with while count = 0 while (count < 3): count = count + 1 print("Hello") else: print("In Else Block")
  • 24. Colors, Charts, and Icons For Loop in Python:- For loops are used for sequential traversal. For example: traversing a list or string or array etc. In Python, there is “for in” loop which is similar to for each loop in other languages. Let us learn how to use for in loop for sequential traversals. # Python program to illustrate # Iterating over range 0 to n-1 n = 4 for i in range(0, n): print(i) output? Decrementing With range(): for i in range(10, -6, -2): print(i) This will start at 10 and count down by 2 until you reach -6, or rather -4 because you don’t include -6. This will start at 10 and count down by 2 until you reach -6, or rather -4 because you don’t include -6.
  • 25. Colors, Charts, and Icons Nested Loops:- Python programming language allows to use one loop inside another loop. We will use nested loop to print right angle triangle star pattern. Let’s see how this work: for i in range(1, 5): for j in range(i): print(i, end=' ') print() what is end here? # ends the output with a space print("Welcome to", end = ' ') print("GeeksforGeeks", end= ' ') Print statement automatically print a new line after the prompt inside it. To prevent creating new line and to continue with same line we use end=“ ”
  • 26. Star Patterns:- Example: for i in range(1, 9): for j in range(i): print(“*”, end=' ') print() Python Print Star Patterns 14 Programs https://easycodebook.com/2021/05/python-print-star-pattern-shapes-programs/