# looping through list
= ['Agriculture', 'Soil Science', 'Francisation', 'génie civil']
courses for course in courses:
print(course)
Agriculture
Soil Science
Francisation
génie civil
Python basics
Kunal Khurana
October 6, 2023
# looping through list
courses = ['Agriculture', 'Soil Science', 'Francisation', 'génie civil']
for course in courses:
print(course)
Agriculture
Soil Science
Francisation
génie civil
Agriculture, was awesome!
Soil Science, was awesome!
Francisation, was awesome!
Génie Civil, was awesome!
# adding a line in front
for course in courses:
print (f"I look forward to becoming more smart in {course.title()}.")
I look forward to becoming more smart in Agriculture.
I look forward to becoming more smart in Soil Science.
I look forward to becoming more smart in Francisation.
I look forward to becoming more smart in Génie Civil.
# adding an empty line after
for course in courses:
print (f"I will add empty line after {course.title()}.\n")
I will add empty line after Agriculture.
I will add empty line after Soil Science.
I will add empty line after Francisation.
I will add empty line after Génie Civil.
# way to write multiple lines of code using for loop
for course in courses:
print(f"{course.title()} was a great subject")
print(f"I got to learn a lot about {course.title()}.")
print("Thanks awesome people who came to my life as mentors and changed it.\n")
Agriculture was a great subject
I got to learn a lot about Agriculture.
Thanks awesome people who came to my life as mentors and changed it.
Soil Science was a great subject
I got to learn a lot about Soil Science.
Thanks awesome people who came to my life as mentors and changed it.
Francisation was a great subject
I got to learn a lot about Francisation.
Thanks awesome people who came to my life as mentors and changed it.
Génie Civil was a great subject
I got to learn a lot about Génie Civil.
Thanks awesome people who came to my life as mentors and changed it.
list[1]
list[2]
list[3]
list[4]
list[5]
[1, 2, 3, 4, 5]
squares = []
for value in range(1,11):
square = value ** 2
squares.append(square)
print(squares)
print (squares) #difference between this and previous, wow!
# indentation is important
[1]
[1, 4]
[1, 4, 9]
[1, 4, 9, 16]
[1, 4, 9, 16, 25]
[1, 4, 9, 16, 25, 36]
[1, 4, 9, 16, 25, 36, 49]
[1, 4, 9, 16, 25, 36, 49, 64]
[1, 4, 9, 16, 25, 36, 49, 64, 81]
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
[1, 8, 27, 64, 125, 216, 343, 512, 729, 1000]
('Aloo gobhi', 'matar paneer', 'parantha', 'raita', 'roti')
Buffet:
Aloo gobhi
matar paneer
parantha
raita
roti
New_buffet = ('raita', 'parantha', 'butternan', 'allogobhi', 'Kasaurimethi')
print('New_buffet:')
for item in New_buffet:
print(item)
New_buffet:
raita
parantha
butternan
allogobhi
Kasaurimethi
Respecting community; some guidelines 1. Indentation- PEP 8 2. line length- 79 characters long 3. Blank lines - 5 lines of code follwoed by a blank line is suggested