Added lecture 2026113
This commit is contained in:
parent
be356ccb59
commit
5b630435ae
27 changed files with 738 additions and 0 deletions
8
lecture20261103/for01/for01.py
Normal file
8
lecture20261103/for01/for01.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
|
||||
|
||||
#https://beginnersbook.com/2018/01/python-for-loop/
|
||||
|
||||
for val in range(5):
|
||||
print(val)
|
||||
else:
|
||||
print("The loop has completed execution")
|
||||
15
lecture20261103/for01/for02.py
Normal file
15
lecture20261103/for01/for02.py
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
# Program to print squares of all numbers present in a list
|
||||
# https://beginnersbook.com/2018/01/python-for-loop/
|
||||
|
||||
# List of integer numbers
|
||||
numbers = [1, 2, 4, 6, 11, 20]
|
||||
|
||||
# variable to store the square of each num temporary
|
||||
sq = 0
|
||||
|
||||
# iterating over the given list
|
||||
for val in numbers:
|
||||
# calculating square of each number
|
||||
sq = val * val
|
||||
# displaying the squares
|
||||
print(sq)
|
||||
26
lecture20261103/for01/for03.py
Normal file
26
lecture20261103/for01/for03.py
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
|
||||
print("\nSome demo range statements\n")
|
||||
|
||||
print("Print a range(6) ")
|
||||
for x in range(6):
|
||||
print(x)
|
||||
else:
|
||||
print("Finally finished!")
|
||||
|
||||
print("\n\nPrint a range(0, 3) ")
|
||||
for x in range(0, 3):
|
||||
print("Value of x = {:d}".format(x) )
|
||||
|
||||
|
||||
print("\n\nPrint a range(45, 55) ")
|
||||
for x in range(45, 55):
|
||||
print("Value of x = {:d}".format(x) )
|
||||
|
||||
|
||||
print("\n\nPrint a range(2, 30, 4) ")
|
||||
for x in range(2, 30, 4):
|
||||
print(x)
|
||||
|
||||
print("\n\nPrint a range(1, 11, 2) ")
|
||||
for x in range(1, 11, 2):
|
||||
print(x)
|
||||
5
lecture20261103/for01/for04.py
Normal file
5
lecture20261103/for01/for04.py
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
|
||||
print("Break a string into characters.")
|
||||
string = "Hello World"
|
||||
for x in string:
|
||||
print(x)
|
||||
7
lecture20261103/for01/for05.py
Normal file
7
lecture20261103/for01/for05.py
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
|
||||
# https://beginnersbook.com/2018/01/python-for-loop/
|
||||
|
||||
for num1 in range(0,3):
|
||||
for num2 in range(0, 3):
|
||||
print(num1, ",", num2)
|
||||
|
||||
12
lecture20261103/for01/for06.py
Normal file
12
lecture20261103/for01/for06.py
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
# https://www.programiz.com/python-programming/for-loop
|
||||
scores = [70, 91, 85, 90, 100]
|
||||
|
||||
print(f"The length of this list of scores is {len(scores)}")
|
||||
|
||||
scoreSum = 0
|
||||
for i in scores:
|
||||
print(i)
|
||||
scoreSum += i
|
||||
else:
|
||||
print("The average is ",scoreSum/len(scores))
|
||||
Loading…
Add table
Add a link
Reference in a new issue