Skip to content

Commit eee2e4b

Browse files
committed
added comments
1 parent 38a1111 commit eee2e4b

7 files changed

Lines changed: 86 additions & 76 deletions

Dictionary.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
2-
3-
41
def main():
5-
#Student={'Name':"hussein alrubaye",'Age':27,'Slary':232.5};
6-
Student=dict(Name="hussein alrubaye",Age=27,Slary=232.5);
7-
Student['Name']="Hussein Ahmed"
8-
Student["Dept"]="software engineer"
9-
print(Student,type(Student))
2+
# Student={'Name':"hussein alrubaye",'Age':27,'Salary':232.5};
3+
Student = dict(Name="hussein alrubaye", Age=27, Salary=232.5)
4+
print(Student)
5+
# Replacing the earlier student with another student.
6+
Student["Name"] = "Hussein Ahmed"
7+
Student["Dept"] = "software engineer"
8+
print(Student, type(Student))
9+
# Deleting the value Dept and it's value.
1010
del Student["Dept"]
11-
print(Student,type(Student))
12-
print(Student['Name'])
13-
print(Student['Age'])
11+
print(Student, type(Student))
12+
print(Student["Name"])
13+
print(Student["Age"])
14+
# Clearing the Student dictionary.
1415
Student.clear()
15-
print(Student,type(Student))
16-
17-
16+
print(Student, type(Student))
1817

1918

20-
if __name__ == '__main__':main()
19+
if __name__ == "__main__":
20+
main()

condition_if_simple.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
# A function called main
12
def main():
2-
Age=input("enter your Age:")
3-
if(int(Age)>18):
3+
# Age takes input as age.
4+
Age = input("enter your Age:")
5+
# checks if the age is above 18
6+
# it would not work if Age entered is a string.
7+
if int(Age) > 18:
48
print("welcome")
59

610

7-
8-
9-
10-
if __name__ == '__main__':main()
11+
# Again if the function is within the program it would
12+
# call the main() function
13+
if __name__ == "__main__":
14+
main()

conditional_if_elif.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
def main():
2-
Age=input("enter your Age:")
3-
if(int(Age)>=8 and int(Age)<=10):
2+
Age = input("enter your Age:")
3+
# If statement that checks age within 8 and 10
4+
# Including 8 and 10
5+
# Prints children 4 times.
6+
if int(Age) >= 8 and int(Age) <= 10:
47
print("children")
58
print("children")
69
print("children")
710
print("children")
8-
elif(int(Age)>=11 and int(Age)<=15):
9-
print("kids")
10-
elif(int(Age)>=16 and int(Age)<=18):
11-
print("Tingers")
12-
elif(int(Age)>=19 and int(Age)<=30):
13-
print("Young")
11+
elif int(Age) >= 11 and int(Age) <= 15:
12+
print("Kids")
13+
elif int(Age) >= 16 and int(Age) <= 18:
14+
print("Teenagers")
15+
elif int(Age) >= 19 and int(Age) <= 30:
16+
print("Youngsters")
1417
else:
15-
print("Out of range")
18+
print("Boomers")
1619
print("End")
1720

1821

19-
20-
21-
22-
if __name__ == '__main__':main()
22+
if __name__ == "__main__":
23+
main()

conditional_if_else.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
def main():
2-
Age=input("enter your Age:")
3-
if(int(Age)>18):
2+
Age = input("enter your Age:")
3+
if int(Age) > 18:
44
print("welcome")
55
else:
66
print("Not Welcome")
77

88

9-
10-
11-
12-
13-
if __name__ == '__main__':main()
9+
if __name__ == "__main__":
10+
main()

conditional_nested_if.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
def main():
2-
Degree=input("enter your Degree:")
3-
if(int(Degree)>=90 ):
4-
print("hi")
5-
x=5
6-
if(int(Degree)>94):
7-
print("Your Score is +A")
2+
Degree = input("Enter your Degree:")
3+
# There are 2 conditions if you get above 90.
4+
if int(Degree) >= 90:
5+
print("Hiya!!!")
6+
x = 5
7+
if int(Degree) > 94:
8+
print("Your Score is A+")
89
else:
9-
print("Your Score is -A")
10-
elif(int(Degree)>=80 and int(Degree)<=89):
10+
print("Your Score is A-")
11+
# Conditions if you get below 90.
12+
elif int(Degree) >= 80 and int(Degree) <= 89:
1113
print("Your Score is B")
12-
elif(int(Degree)>=70 and int(Degree)<=79):
14+
elif int(Degree) >= 70 and int(Degree) <= 79:
1315
print("Your Score is C")
14-
elif(int(Degree)>=60 and int(Degree)<=69):
16+
elif int(Degree) >= 60 and int(Degree) <= 69:
1517
print("Your Score is D")
16-
elif(int(Degree)>=50 and int(Degree)<=59):
18+
elif int(Degree) >= 50 and int(Degree) <= 59:
1719
print("Your Score is E")
1820
else:
1921
print("You Fail")
20-
2122

22-
if __name__ == '__main__':main()
23+
24+
if __name__ == "__main__":
25+
main()

database.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
1-
2-
3-
4-
51
import sqlite3
62

3+
74
def main():
8-
db=sqlite3.connect("information.db")
9-
db.row_factory=sqlite3.Row
5+
# Connection to a database called information.db
6+
db = sqlite3.connect("information.db")
7+
# row_factory returns everything as a ditionary rather that a tuple.
8+
db.row_factory = sqlite3.Row
9+
# creates a table with 4 columns.
10+
# Name would be text and age would be int.
1011
db.execute("create table if not exists Admin(Name text,age int)")
11-
db.execute("insert into Admin (Name,age) values (? , ?)",("Hussein",26))
12-
db.execute("insert into Admin (Name,age) values (? , ?)",("Jena",1))
12+
db.execute("insert into Admin (Name,age) values (? , ?)", ("Hussein", 26))
13+
db.execute("insert into Admin (Name,age) values (? , ?)", ("Jena", 1))
1314
db.commit()
14-
#db.execute("delete from Admin where name='Jena'")
15-
#db.execute("Update Admin set age=2 where name='Jena'")
16-
cusror=db.execute("select * from Admin")
17-
for row in cusror:
18-
print("Name:{}, Age:{}".format(row["Name"],row["age"]))
15+
# You could delete the entire row with Jena a the Name.
16+
# db.execute("delete from Admin where name='Jena'")
1917

18+
# db.execute("Update Admin set age=2 where name='Jena'")
2019

20+
# Selecting all from admin
21+
cusror = db.execute("select * from Admin")
22+
for row in cusror:
23+
print("Name:{}, Age:{}".format(row["Name"], row["age"]))
2124

2225

23-
if __name__ == '__main__':main()
26+
if __name__ == "__main__":
27+
main()

exceptions.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
2-
3-
4-
51
def main():
62
try:
7-
readFile=open("test.txt","r")
3+
# We try to open a file and store it in readFile.
4+
# We do so with r parameter which is read.
5+
readFile = open("test.txt", "r")
6+
# Print each line.
87
for line in readFile:
98
print(line)
9+
# We close the file.
1010
readFile.close()
11+
1112
except IOError:
1213
print("File not found")
1314
else:
14-
print("File is readed")
15-
15+
print("File is read")
1616

1717

18-
if __name__ == '__main__':main()
18+
if __name__ == "__main__":
19+
main()

0 commit comments

Comments
 (0)