Skip to content

Commit

Permalink
Add Control Flow
Browse files Browse the repository at this point in the history
  • Loading branch information
mrthetkhine committed Sep 2, 2021
1 parent 88313c7 commit 026670b
Show file tree
Hide file tree
Showing 13 changed files with 135 additions and 0 deletions.
3 changes: 3 additions & 0 deletions chapter4/c_style_loop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#1,3,5,7,9
for i in range(10,0,-2):
print("i ",i)
3 changes: 3 additions & 0 deletions chapter4/day_of_week.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
week_days =["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Sat"]
day_of_week = int(input("Enter day of the week "))
print("Day of the week ", week_days[day_of_week])
7 changes: 7 additions & 0 deletions chapter4/dict_loop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
my_dict = {"user1":"Aung Aung","user2":"Maung Maung"}

for i in my_dict:
print("Item ", i)

for key,value in my_dict.items():
print("Key=> ",key, " value =>",value)
11 changes: 11 additions & 0 deletions chapter4/double_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
my_list = [10,20,30,40]

for i in my_list:
print("I is ",i)
i *= 2

for i in range(len(my_list)):
print("Item ",my_list[i])
my_list[i] = my_list[i] * 2

print("My list ",my_list)
11 changes: 11 additions & 0 deletions chapter4/exam.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
myanmar = float(input("Enter mark for myanmar "))
english = float(input("Enter mark for english "))
math = float(input("Enter mark for math "))

pass_mark = 40
if myanmar >= pass_mark and english >= pass_mark and math >= pass_mark:
print("Pass the exam")
else:
print("Fail")

print("Code end")
10 changes: 10 additions & 0 deletions chapter4/exam_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
myanmar = float(input("Enter mark for myanmar "))
english = float(input("Enter mark for english "))
math = float(input("Enter mark for math "))

if myanmar < 40 or english < 40 or math < 40:
print("Fail")
else:
print("Pass")

print("Code end")
16 changes: 16 additions & 0 deletions chapter4/exam_3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
myanmar = float(input("Enter mark for myanmar "))
english = float(input("Enter mark for english "))
math = float(input("Enter mark for math "))

if myanmar >= 40:
if english >= 40:
if math >= 40:
print("Pass ")
else:
print("Fail")
else:
print("Fail")
else:
print("Fail")

print("Code end")
14 changes: 14 additions & 0 deletions chapter4/exam_4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
number_of_subject = int(input("Enter number of subject "))
#marks = []

pass_mark = 40
isPass = True

for i in range(number_of_subject):
mark = float(input("Enter mark for subject "+str(i)+" ") )
isPass = isPass and mark >=40

if isPass:
print("Pass the exam ")
else:
print("Fail the exam")
9 changes: 9 additions & 0 deletions chapter4/for_else.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
my_list = [1,2,3,4]

for i in my_list:
print("Item ",i)
if i==13:
break
else:
print("for complete normally")
print("end of loop")
21 changes: 21 additions & 0 deletions chapter4/for_in_loop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
str = "Hello"

for i in str:
print("Char ",i)

print("End of loop ",i)

my_list = ["one","two","three","four","five"]

for item in my_list:
print("Item ",item)

my_dict = {"1":"Red","2":"Green",3:"Blue"}

for item in my_dict:
print("Item in dic ",item)

my_set = ("Orange","Banana","Apple")

for item in my_set:
print("Item ",item)
13 changes: 13 additions & 0 deletions chapter4/hello_loop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
print("Hello World")
print("Hello World")
print("Hello World")
print("Hello World")
print("Hello World")
print("Hello World")
print("Hello World")
print("Hello World")
print("Hello World")
print("Hello World")
print("Hello World")
print("Hello World")
print("Hello World")
7 changes: 7 additions & 0 deletions chapter4/hello_loop_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
print("Range ", range(3))

for i in range(3):
print("Hello ",i)
print("World ")

print("End of loop ",i)
10 changes: 10 additions & 0 deletions chapter4/if_Truthy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

if "Hello":
print("Hello")
print("Code end")

str = ''
if str:
print("Cannot see this")
else:
print("Will print this")

0 comments on commit 026670b

Please sign in to comment.