commit d5ddbfda71b9cc78663d57bd897842dfb57e84e7 Author: Uthman Fatih Date: Thu Aug 27 16:40:55 2026 +0100 completed up to exercise 10: using data and time diff --git a/01 Calculate using Python/exercise-01.py b/01 Calculate using Python/exercise-01.py new file mode 100644 index 0000000..6de605d --- /dev/null +++ b/01 Calculate using Python/exercise-01.py @@ -0,0 +1,10 @@ +print(50-5*6) +print((50-5*6)/4) +print(8/5) +print(4*3) +print(12/3) +print(21&6) +print(17//5) +print(5*3+2) +print(5**2) +print(1//2) \ No newline at end of file diff --git a/01 Calculate using Python/task.png b/01 Calculate using Python/task.png new file mode 100644 index 0000000..c2f411b Binary files /dev/null and b/01 Calculate using Python/task.png differ diff --git a/02 Variables and Assignment/exercise-02.py b/02 Variables and Assignment/exercise-02.py new file mode 100644 index 0000000..5a86702 --- /dev/null +++ b/02 Variables and Assignment/exercise-02.py @@ -0,0 +1,11 @@ +from decimal import Decimal +import math + +# Use Decimal for bcd (binary coded decimal) to avoid floating point errors +radius = Decimal('6.7') + +pi = Decimal(str(math.pi)) + +area = pi * (radius ** 2) + +print(f"{area}cm²") \ No newline at end of file diff --git a/02 Variables and Assignment/exercise-03.py b/02 Variables and Assignment/exercise-03.py new file mode 100644 index 0000000..70cfbed --- /dev/null +++ b/02 Variables and Assignment/exercise-03.py @@ -0,0 +1,15 @@ + +name = input("Please enter your name: ").split(" ") +forename = name[0] +surname = name[-1] # handle the case where a middle name is supplied + +age = int(input("How old are you? ")) + +height = int(input("How tall are you (cm)? ")) + +def display_info(forename, surname, age, height): + print(f"Hello {forename.capitalize()} {surname.capitalize()}! You are {age} years old and {height}cm tall.") + # uthman fatih to ufatih + print(f"Your username is {forename.lower()[0]}{surname.lower()}") + +display_info(forename, surname, age, height) diff --git a/02 Variables and Assignment/task.png b/02 Variables and Assignment/task.png new file mode 100644 index 0000000..b06da14 Binary files /dev/null and b/02 Variables and Assignment/task.png differ diff --git a/03 Strings/exercise-01.py b/03 Strings/exercise-01.py new file mode 100644 index 0000000..67e283f --- /dev/null +++ b/03 Strings/exercise-01.py @@ -0,0 +1,5 @@ +name = input("Please enter your name: ").split(" ") +for i in range(len(name)): + name[i] = name[i].capitalize() +name = " ".join(name) +print(f"Hello {name}! \nI hope you are doing well.") \ No newline at end of file diff --git a/03 Strings/exercise-02.py b/03 Strings/exercise-02.py new file mode 100644 index 0000000..5c997c9 --- /dev/null +++ b/03 Strings/exercise-02.py @@ -0,0 +1,21 @@ +numbers = input("Please enter two numbers: ") + +# if numbers variable containers , split by , else split by space +if "," in numbers: + numbers = numbers.split(",") +else: + numbers = numbers.split(" ") + +# exit if len(numbers) != 2 +if len(numbers) != 2: + print("Please enter two numbers") + exit() + +# convert to int +for i in range(len(numbers)): + numbers[i] = int(numbers[i]) + +# calculate the average +average = sum(numbers) / len(numbers) + +print(f"The average of {numbers[0]} and {numbers[1]} is {average}") \ No newline at end of file diff --git a/03 Strings/exercise-03.py b/03 Strings/exercise-03.py new file mode 100644 index 0000000..0c04043 --- /dev/null +++ b/03 Strings/exercise-03.py @@ -0,0 +1,38 @@ +# Prompt user to enter a key number between 1 and 26 +# output the original string and encrypted string + +print(r""" +_________ +\_ ___ \_____ ____ ___________ _______ +/ \ \/\__ \ _/ __ \ / ___/\__ \\_ __ \ +\ \____/ __ \\ ___/ \___ \ / __ \| | \/ + \______ (____ /\___ >____ >(____ /__| + \/ \/ \/ \/ \/ + """) + +original = """ +If he had anything confidential to say, +he wrote it in cipher, +that is, by so changing the order of the letters of the alphabet, +that not a word could be made out. +""" + +key = int(input("Please enter a key number between 1 and 26: ")) + +if key < 1 or key > 26: + print("Please enter a key number between 1 and 26") + exit() + +encrypted = "" + +for i in range(len(original)): + if original[i].isalpha(): + if original[i].isupper(): + encrypted += chr((ord(original[i].lower()) - ord('a') + key) % 26 + ord('A')) + else: + encrypted += chr((ord(original[i].lower()) - ord('a') + key) % 26 + ord('a')) + else: + encrypted += original[i] + +print(f"The original string is: {original}") +print(f"\nThe encrypted string is: {encrypted}") diff --git a/03 Strings/task.png b/03 Strings/task.png new file mode 100644 index 0000000..3825753 Binary files /dev/null and b/03 Strings/task.png differ diff --git a/04 Basic Function/BasicFunction1.py b/04 Basic Function/BasicFunction1.py new file mode 100644 index 0000000..acb95d5 --- /dev/null +++ b/04 Basic Function/BasicFunction1.py @@ -0,0 +1,18 @@ +def add(a, b): + """ add a and b and print the output """ + print(a + b) # print the result + +x = 17 +y = 22 + +add(x, y) + +def multiply_divide(a, b, z): + """ multiply a and b and divide by z """ + return(a * b / z) # return the result + +x = 6 +y = 4 +z = 8 + +print(multiply_divide(x, y, z)) \ No newline at end of file diff --git a/04 Basic Function/task.png b/04 Basic Function/task.png new file mode 100644 index 0000000..7be45ee Binary files /dev/null and b/04 Basic Function/task.png differ diff --git a/05 Extend Basic Function/exercise-01.py b/05 Extend Basic Function/exercise-01.py new file mode 100644 index 0000000..d10d99a --- /dev/null +++ b/05 Extend Basic Function/exercise-01.py @@ -0,0 +1,9 @@ +def multiply_divide(a, b, z): + """ multiply a and b and divide by z """ + return(a * b / z) # return the result + +x = 15 +y = 13 +z = 5 + +print(multiply_divide(x, y, z)) \ No newline at end of file diff --git a/05 Extend Basic Function/exercise-02.py b/05 Extend Basic Function/exercise-02.py new file mode 100644 index 0000000..2e21f59 --- /dev/null +++ b/05 Extend Basic Function/exercise-02.py @@ -0,0 +1,5 @@ +def thanks(inp): + """ print a string and follow it by 'You're welcome' """ + print(inp + " You're welcome") + +thanks("There are only 10 types of people in the world.") \ No newline at end of file diff --git a/05 Extend Basic Function/task.png b/05 Extend Basic Function/task.png new file mode 100644 index 0000000..2e2b7ca Binary files /dev/null and b/05 Extend Basic Function/task.png differ diff --git a/06 Returning Values/exercise-01.py b/06 Returning Values/exercise-01.py new file mode 100644 index 0000000..331440b --- /dev/null +++ b/06 Returning Values/exercise-01.py @@ -0,0 +1,33 @@ +def get_name(): + """ ask for a name and return it """ + name = input("What is your name? ") + return name + +def get_cs_teacher_name(): + """ ask for a students cs teacher's name and return it """ + name = input("What is your CS teacher's name? ") + return name + +def average_homework(): + """ get the score out of 10 for the last 4 homework assignments and average them """ + test_scores = [] + for i in range(4): + score = int(input("What is the score for assignment " + str(i+1) + "? ")) + test_scores.append(score) + + return sum(test_scores)/4 + +name = get_name() +teacher_name = get_cs_teacher_name() +average = average_homework() + +# if average >= 8: well done {name}, {teacher_name} is very pleased with your effort +# if average >= 6 > 8: A good effort {name}, {teacher_name} thinks you should check your work carefully +# if average >= 5: {name} this is very poor, {teacher_name} has asked you to try harder + +if average >= 8: + print(f"Well done {name}, {teacher_name} is very pleased with your effort") +elif average >= 6: + print(f"A good effort {name}, {teacher_name} thinks you should check your work carefully") +elif average >= 5: + print(f"{name} this is very poor, {teacher_name} has asked you to try harder") \ No newline at end of file diff --git a/06 Returning Values/task.png b/06 Returning Values/task.png new file mode 100644 index 0000000..93dfbf5 Binary files /dev/null and b/06 Returning Values/task.png differ diff --git a/07 Relational and Logical Operators/exercise-01.py b/07 Relational and Logical Operators/exercise-01.py new file mode 100644 index 0000000..77c937c --- /dev/null +++ b/07 Relational and Logical Operators/exercise-01.py @@ -0,0 +1,3 @@ +print(23!=15) +print(5+3<10) +print(6>10==10<2) \ No newline at end of file diff --git a/07 Relational and Logical Operators/exercise-02.py b/07 Relational and Logical Operators/exercise-02.py new file mode 100644 index 0000000..8c1152a --- /dev/null +++ b/07 Relational and Logical Operators/exercise-02.py @@ -0,0 +1,7 @@ +a = 3 +b = 8 + +print(a= a) +print(b > a == False) +print(True !=(a==b)) \ No newline at end of file diff --git a/07 Relational and Logical Operators/exercise-03.py b/07 Relational and Logical Operators/exercise-03.py new file mode 100644 index 0000000..53e6154 --- /dev/null +++ b/07 Relational and Logical Operators/exercise-03.py @@ -0,0 +1,6 @@ +c = True +d = False + +print(c and d) +print(not c or d) +print(c == d and True) \ No newline at end of file diff --git a/07 Relational and Logical Operators/task.png b/07 Relational and Logical Operators/task.png new file mode 100644 index 0000000..7049916 Binary files /dev/null and b/07 Relational and Logical Operators/task.png differ diff --git a/08 IF&ELIF Statements/exercise-01.py b/08 IF&ELIF Statements/exercise-01.py new file mode 100644 index 0000000..7384db0 --- /dev/null +++ b/08 IF&ELIF Statements/exercise-01.py @@ -0,0 +1,14 @@ +running = True + +while running: + num = int(input("Enter a number between 1 and 20: ")) + if num < 1: + print("Incorrect entry. Number NOT between 1 & 20.") + continue + elif num > 20: + print("Incorrect entry. Number NOT between 1 & 20.") + continue + + print("Thank you. Number within correct range.") + running = False + \ No newline at end of file diff --git a/08 IF&ELIF Statements/exercise-02.py b/08 IF&ELIF Statements/exercise-02.py new file mode 100644 index 0000000..db13c0b --- /dev/null +++ b/08 IF&ELIF Statements/exercise-02.py @@ -0,0 +1,20 @@ +# get names of two football teams and their scores +# 3 points if they win, 1 for draw, 0 for loss + +WIN = 3 +DRAW = 1 +LOSS = 0 + +team1 = input("Enter the name of the first team: ") +team2 = input("Enter the name of the second team: ") +score1 = int(input("Enter the score of the first team: ")) +score2 = int(input("Enter the score of the second team: ")) + +if score1 > score2: + print(f"{team1} wins with a score of {WIN}") + print(f"{team2} loses with a score of {LOSS}") +elif score1 < score2: + print(f"{team2} wins with a score of {WIN}") + print(f"{team1} loses with a score of {LOSS}") +else: + print(f"The teams tied with a score of {DRAW}") diff --git a/08 IF&ELIF Statements/task.png b/08 IF&ELIF Statements/task.png new file mode 100644 index 0000000..ba33736 Binary files /dev/null and b/08 IF&ELIF Statements/task.png differ diff --git a/09 While and For Loops/exercise-01.py b/09 While and For Loops/exercise-01.py new file mode 100644 index 0000000..deff5af --- /dev/null +++ b/09 While and For Loops/exercise-01.py @@ -0,0 +1,10 @@ +# enter number between 1 and 12 print times tables + +num = int(input("Enter a number between 1 and 12: ")) + +if num < 1 or num > 12: + print("Incorrect entry. Number NOT between 1 & 12.") + exit() + +for i in range(1, 13): + print(f"{num} x {i} = {num * i}") diff --git a/09 While and For Loops/exercise-02.py b/09 While and For Loops/exercise-02.py new file mode 100644 index 0000000..8455f67 --- /dev/null +++ b/09 While and For Loops/exercise-02.py @@ -0,0 +1,23 @@ +def calculate_sum(): + """Continuously prompts for numbers using a while loop until 0 is entered.""" + total = 0 + while True: + num = float(input("Enter a number (or 0 to finish): ")) + if num == 0: + break + total += num + return total + +def display_total(total_value): + """Displays the final calculated sum using parameter passing.""" + if total_value.is_integer(): + print(f"\nThe final total is: {int(total_value)}") + else: + print(f"\nThe final total is: {total_value}") + +def main(): + final_sum = calculate_sum() + display_total(final_sum) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/09 While and For Loops/task.png b/09 While and For Loops/task.png new file mode 100644 index 0000000..8f227d7 Binary files /dev/null and b/09 While and For Loops/task.png differ diff --git a/10 Using Data and Time/exercise-01.py b/10 Using Data and Time/exercise-01.py new file mode 100644 index 0000000..eebc092 --- /dev/null +++ b/10 Using Data and Time/exercise-01.py @@ -0,0 +1,2 @@ +import time + diff --git a/10 Using Data and Time/task.png b/10 Using Data and Time/task.png new file mode 100644 index 0000000..13891e4 Binary files /dev/null and b/10 Using Data and Time/task.png differ diff --git a/11/image.png b/11/image.png new file mode 100644 index 0000000..92d1694 Binary files /dev/null and b/11/image.png differ diff --git a/12/image.png b/12/image.png new file mode 100644 index 0000000..15916ea Binary files /dev/null and b/12/image.png differ diff --git a/13/image.png b/13/image.png new file mode 100644 index 0000000..1595736 Binary files /dev/null and b/13/image.png differ diff --git a/14/image.png b/14/image.png new file mode 100644 index 0000000..a59d3d3 Binary files /dev/null and b/14/image.png differ diff --git a/15/image.png b/15/image.png new file mode 100644 index 0000000..6cf561b Binary files /dev/null and b/15/image.png differ diff --git a/16/image.png b/16/image.png new file mode 100644 index 0000000..9b6a5e4 Binary files /dev/null and b/16/image.png differ