diff --git a/Dictionary.py b/Dictionary.py index 026ded0..95388b0 100644 --- a/Dictionary.py +++ b/Dictionary.py @@ -1,20 +1,20 @@ - - - def main(): - #Student={'Name':"hussein alrubaye",'Age':27,'Slary':232.5}; - Student=dict(Name="hussein alrubaye",Age=27,Slary=232.5); - Student['Name']="Hussein Ahmed" - Student["Dept"]="software engineer" - print(Student,type(Student)) + # Student={'Name':"hussein alrubaye",'Age':27,'Salary':232.5}; + Student = dict(Name="hussein alrubaye", Age=27, Salary=232.5) + print(Student) + # Replacing the earlier student with another student. + Student["Name"] = "Hussein Ahmed" + Student["Dept"] = "software engineer" + print(Student, type(Student)) + # Deleting the value Dept and it's value. del Student["Dept"] - print(Student,type(Student)) - print(Student['Name']) - print(Student['Age']) + print(Student, type(Student)) + print(Student["Name"]) + print(Student["Age"]) + # Clearing the Student dictionary. Student.clear() - print(Student,type(Student)) - - + print(Student, type(Student)) -if __name__ == '__main__':main() +if __name__ == "__main__": + main() diff --git a/condition_if_simple.py b/condition_if_simple.py index de2085e..1ffeeda 100644 --- a/condition_if_simple.py +++ b/condition_if_simple.py @@ -1,10 +1,14 @@ +# A function called main def main(): - Age=input("enter your Age:") - if(int(Age)>18): + # Age takes input as age. + Age = input("enter your Age:") + # checks if the age is above 18 + # it would not work if Age entered is a string. + if int(Age) > 18: print("welcome") - - - -if __name__ == '__main__':main() \ No newline at end of file +# Again if the function is within the program it would +# call the main() function +if __name__ == "__main__": + main() diff --git a/conditional_if_elif.py b/conditional_if_elif.py index 8ae7e05..92399fa 100644 --- a/conditional_if_elif.py +++ b/conditional_if_elif.py @@ -1,22 +1,23 @@ def main(): - Age=input("enter your Age:") - if(int(Age)>=8 and int(Age)<=10): + Age = input("enter your Age:") + # If statement that checks age within 8 and 10 + # Including 8 and 10 + # Prints children 4 times. + if int(Age) >= 8 and int(Age) <= 10: print("children") print("children") print("children") print("children") - elif(int(Age)>=11 and int(Age)<=15): - print("kids") - elif(int(Age)>=16 and int(Age)<=18): - print("Tingers") - elif(int(Age)>=19 and int(Age)<=30): - print("Young") + elif int(Age) >= 11 and int(Age) <= 15: + print("Kids") + elif int(Age) >= 16 and int(Age) <= 18: + print("Teenagers") + elif int(Age) >= 19 and int(Age) <= 30: + print("Youngsters") else: - print("Out of range") + print("Boomers") print("End") - - - -if __name__ == '__main__':main() \ No newline at end of file +if __name__ == "__main__": + main() diff --git a/conditional_if_else.py b/conditional_if_else.py index af88d69..5758c97 100644 --- a/conditional_if_else.py +++ b/conditional_if_else.py @@ -1,13 +1,10 @@ def main(): - Age=input("enter your Age:") - if(int(Age)>18): + Age = input("enter your Age:") + if int(Age) > 18: print("welcome") else: print("Not Welcome") - - - - -if __name__ == '__main__':main() \ No newline at end of file +if __name__ == "__main__": + main() diff --git a/conditional_nested_if.py b/conditional_nested_if.py index c657daf..8bbf10f 100644 --- a/conditional_nested_if.py +++ b/conditional_nested_if.py @@ -1,22 +1,25 @@ def main(): - Degree=input("enter your Degree:") - if(int(Degree)>=90 ): - print("hi") - x=5 - if(int(Degree)>94): - print("Your Score is +A") + Degree = input("Enter your Degree:") + # There are 2 conditions if you get above 90. + if int(Degree) >= 90: + print("Hiya!!!") + x = 5 + if int(Degree) > 94: + print("Your Score is A+") else: - print("Your Score is -A") - elif(int(Degree)>=80 and int(Degree)<=89): + print("Your Score is A-") + # Conditions if you get below 90. + elif int(Degree) >= 80 and int(Degree) <= 89: print("Your Score is B") - elif(int(Degree)>=70 and int(Degree)<=79): + elif int(Degree) >= 70 and int(Degree) <= 79: print("Your Score is C") - elif(int(Degree)>=60 and int(Degree)<=69): + elif int(Degree) >= 60 and int(Degree) <= 69: print("Your Score is D") - elif(int(Degree)>=50 and int(Degree)<=59): + elif int(Degree) >= 50 and int(Degree) <= 59: print("Your Score is E") else: print("You Fail") - -if __name__ == '__main__':main() \ No newline at end of file + +if __name__ == "__main__": + main() diff --git a/database.py b/database.py index 702c559..970a414 100644 --- a/database.py +++ b/database.py @@ -1,23 +1,27 @@ - - - - import sqlite3 + def main(): - db=sqlite3.connect("information.db") - db.row_factory=sqlite3.Row + # Connection to a database called information.db + db = sqlite3.connect("information.db") + # row_factory returns everything as a ditionary rather that a tuple. + db.row_factory = sqlite3.Row + # creates a table with 4 columns. + # Name would be text and age would be int. db.execute("create table if not exists Admin(Name text,age int)") - db.execute("insert into Admin (Name,age) values (? , ?)",("Hussein",26)) - db.execute("insert into Admin (Name,age) values (? , ?)",("Jena",1)) + db.execute("insert into Admin (Name,age) values (? , ?)", ("Hussein", 26)) + db.execute("insert into Admin (Name,age) values (? , ?)", ("Jena", 1)) db.commit() - #db.execute("delete from Admin where name='Jena'") - #db.execute("Update Admin set age=2 where name='Jena'") - cusror=db.execute("select * from Admin") - for row in cusror: - print("Name:{}, Age:{}".format(row["Name"],row["age"])) + # You could delete the entire row with Jena a the Name. + # db.execute("delete from Admin where name='Jena'") + # db.execute("Update Admin set age=2 where name='Jena'") + # Selecting all from admin + cusror = db.execute("select * from Admin") + for row in cusror: + print("Name:{}, Age:{}".format(row["Name"], row["age"])) -if __name__ == '__main__':main() +if __name__ == "__main__": + main() diff --git a/exceptions.py b/exceptions.py index 063d501..08495e9 100644 --- a/exceptions.py +++ b/exceptions.py @@ -1,18 +1,19 @@ - - - - def main(): try: - readFile=open("test.txt","r") + # We try to open a file and store it in readFile. + # We do so with r parameter which is read. + readFile = open("test.txt", "r") + # Print each line. for line in readFile: print(line) + # We close the file. readFile.close() + except IOError: print("File not found") else: - print("File is readed") - + print("File is read") -if __name__ == '__main__':main() +if __name__ == "__main__": + main()