From 9c99c5235889552a2867f11eea6282f72fa56718 Mon Sep 17 00:00:00 2001 From: Dukeson Ehigboria O Date: Tue, 14 Mar 2023 17:55:57 +0100 Subject: [PATCH 01/11] Solution to task --- Exercises/Advanced Tasks/Ballpark-orders.py | 19 --------------- Exercises/Advanced Tasks/halloween-candy.py | 20 ---------------- .../Advanced Tasks/new-drivers-license.py | 22 ------------------ Exercises/Advanced Tasks/pig-latin.py | 15 ------------ .../Advanced Tasks/safety-deposit-boxes.py | 23 ------------------- Exercises/Conditional Statements/task1.py | 2 -- Exercises/Conditional Statements/task2.py | 2 -- Exercises/Conditional Statements/task3.py | 2 -- Exercises/Conditional Statements/task4.py | 2 -- Exercises/Conditional Statements/task5.py | 2 -- Exercises/Data Types and Variables/task1.py | 9 +++++++- Exercises/Data Types and Variables/task2.py | 11 ++++++++- Exercises/Data Types and Variables/task3.py | 11 ++++++++- Exercises/Modules/task1.py | 4 ---- Exercises/Modules/task2.py | 5 ---- Exercises/Modules/task3.py | 6 ----- Exercises/Modules/task4.py | 5 ---- Exercises/Operators/task1.py | 14 ++++++++++- Exercises/Operators/task2.py | 6 ++++- Exercises/Operators/task3.py | 11 ++++++++- 20 files changed, 56 insertions(+), 135 deletions(-) delete mode 100644 Exercises/Advanced Tasks/Ballpark-orders.py delete mode 100644 Exercises/Advanced Tasks/halloween-candy.py delete mode 100644 Exercises/Advanced Tasks/new-drivers-license.py delete mode 100644 Exercises/Advanced Tasks/pig-latin.py delete mode 100644 Exercises/Advanced Tasks/safety-deposit-boxes.py delete mode 100644 Exercises/Conditional Statements/task1.py delete mode 100644 Exercises/Conditional Statements/task2.py delete mode 100644 Exercises/Conditional Statements/task3.py delete mode 100644 Exercises/Conditional Statements/task4.py delete mode 100644 Exercises/Conditional Statements/task5.py delete mode 100644 Exercises/Modules/task1.py delete mode 100644 Exercises/Modules/task2.py delete mode 100644 Exercises/Modules/task3.py delete mode 100644 Exercises/Modules/task4.py diff --git a/Exercises/Advanced Tasks/Ballpark-orders.py b/Exercises/Advanced Tasks/Ballpark-orders.py deleted file mode 100644 index a7c9249..0000000 --- a/Exercises/Advanced Tasks/Ballpark-orders.py +++ /dev/null @@ -1,19 +0,0 @@ -# You and three friends go to a baseball game and you offer to go to the concession stand for everyone. -# They each order one thing, and you do as well. Nachos and Pizza both cost $6.00. A Cheeseburger meal costs $10. -# Water is $4.00 and Coke is $5.00. Tax is 7%. - -# Task -# Determine the total cost of ordering four items from the concession stand. If one of your friend’s orders -# something that isn't on the menu, you will order a Coke for them instead. - -# Input Format -# You are given a string of the four items that you've been asked to order that are separated by spaces. - -# Output Format -# You will output a number of the total cost of the food and drinks. - -# Sample Input -# 'Pizza Cheeseburger Water Popcorn' - -# Sample Output -# 26.75 \ No newline at end of file diff --git a/Exercises/Advanced Tasks/halloween-candy.py b/Exercises/Advanced Tasks/halloween-candy.py deleted file mode 100644 index af69fa9..0000000 --- a/Exercises/Advanced Tasks/halloween-candy.py +++ /dev/null @@ -1,20 +0,0 @@ -# You go trick or treating with a friend and all but three of the houses that you visit are giving out candy. -# One house that you visit is giving out toothbrushes and two houses are giving out dollar bills. - -# Task -# Given the input of the total number of houses that you visited, what is the percentage chance that one -# random item pulled from your bag is a dollar bill? - -# Input Format -# An integer (>=3) representing the total number of houses that you visited. - -# Output Format -# A percentage value rounded up to the nearest whole number. - -# Sample Input -# 4 - -# Sample Output -# 50 - -# Write your program below \ No newline at end of file diff --git a/Exercises/Advanced Tasks/new-drivers-license.py b/Exercises/Advanced Tasks/new-drivers-license.py deleted file mode 100644 index 63635d1..0000000 --- a/Exercises/Advanced Tasks/new-drivers-license.py +++ /dev/null @@ -1,22 +0,0 @@ -# You have to get a new driver's license and you show up at the office at the same time as 4 other people. -# The office says that they will see everyone in alphabetical order and it takes 20 minutes for them to process -# each new license. All of the agents are available now, and they can each see one customer at a time. -# How long will it take for you to walk out of the office with your new license? - -# Task -# Given everyone's name that showed up at the same time, determine how long it will take to get your new license. - -# Input Format -# Your input will be a string of your name, then an integer of the number of available agents, and lastly a string of -# the other four names separated by spaces. - -# Output Format -# You will output an integer of the number of minutes that it will take to get your license. - -# Sample Input -# 'Eric' -# 2 -# 'Adam Caroline Rebecca Frank' - -# Sample Output -# 40 \ No newline at end of file diff --git a/Exercises/Advanced Tasks/pig-latin.py b/Exercises/Advanced Tasks/pig-latin.py deleted file mode 100644 index 9415ce3..0000000 --- a/Exercises/Advanced Tasks/pig-latin.py +++ /dev/null @@ -1,15 +0,0 @@ -# You have two friends who are speaking Pig Latin to each other! Pig Latin is the same words in -# the same order except that you take the first letter of each word and put it on the end, then you -# add 'ay' to the end of that. ("road" = "oadray") -# Task -# Your task is to take a sentence in English and turn it into the same sentence in Pig Latin! -# Input Format -# A string of the sentence in English that you need to translate into Pig Latin. (no punctuation or capitalization) -# Output Format -# A string of the same sentence in Pig Latin. -# Sample Input -# "nevermind youve got them" -# Sample Output -# "evermindnay ouveyay otgay hemtay - -# Write your program below \ No newline at end of file diff --git a/Exercises/Advanced Tasks/safety-deposit-boxes.py b/Exercises/Advanced Tasks/safety-deposit-boxes.py deleted file mode 100644 index 8010d66..0000000 --- a/Exercises/Advanced Tasks/safety-deposit-boxes.py +++ /dev/null @@ -1,23 +0,0 @@ -# You are robbing a bank, but you’re not taking everything. You are looking for a specific item in -# the safety deposit boxes and you are going to drill into each one in order to find your item. -# Once you find your item you can make your escape, but how long will it take you to get to that item? - -# Task -# Determine the amount of time it will take you to find the item you are looking for if it takes you 5 -# minutes to drill into each box. - -# Input Format -# A string that represent the items in each box that will be drilled in order (items are separated by a comma), -# and secondly, a string of which item you are looking for. - -# Output Format -# An integer of the amount of time it will take for you to find your item. - -# Sample Input -# 'gold,diamonds,documents,Declaration of Independence,keys' -# 'Declaration of Independence' - -# Sample Output -# 20 - -# Write your program below \ No newline at end of file diff --git a/Exercises/Conditional Statements/task1.py b/Exercises/Conditional Statements/task1.py deleted file mode 100644 index 6bb4ffa..0000000 --- a/Exercises/Conditional Statements/task1.py +++ /dev/null @@ -1,2 +0,0 @@ -# Write a program that takes an integer as input and prints whether it is positive, negative, or zero. -# Write your program below \ No newline at end of file diff --git a/Exercises/Conditional Statements/task2.py b/Exercises/Conditional Statements/task2.py deleted file mode 100644 index 53c1fb6..0000000 --- a/Exercises/Conditional Statements/task2.py +++ /dev/null @@ -1,2 +0,0 @@ -# Write a program that takes two integers as input and prints the larger one. -# Write your program below \ No newline at end of file diff --git a/Exercises/Conditional Statements/task3.py b/Exercises/Conditional Statements/task3.py deleted file mode 100644 index 4d0659e..0000000 --- a/Exercises/Conditional Statements/task3.py +++ /dev/null @@ -1,2 +0,0 @@ -# Write a program that takes a string as input and prints whether it contains the letter "a". -# Write your program below \ No newline at end of file diff --git a/Exercises/Conditional Statements/task4.py b/Exercises/Conditional Statements/task4.py deleted file mode 100644 index 13771cb..0000000 --- a/Exercises/Conditional Statements/task4.py +++ /dev/null @@ -1,2 +0,0 @@ -# Write a program that takes a year as input and prints whether it is a leap year or not. -# Write your program below \ No newline at end of file diff --git a/Exercises/Conditional Statements/task5.py b/Exercises/Conditional Statements/task5.py deleted file mode 100644 index eac52f6..0000000 --- a/Exercises/Conditional Statements/task5.py +++ /dev/null @@ -1,2 +0,0 @@ -# Write a program that takes a number as input and prints whether it is odd or even. -# Write your program below \ No newline at end of file diff --git a/Exercises/Data Types and Variables/task1.py b/Exercises/Data Types and Variables/task1.py index 22e5626..297f598 100644 --- a/Exercises/Data Types and Variables/task1.py +++ b/Exercises/Data Types and Variables/task1.py @@ -1,3 +1,10 @@ +#!/usr/bin/python3 + # Write a Python program that asks the user to enter their name and age, and then prints a message # saying "Hello, [name]! You are [age] years old." -# Write your program below \ No newline at end of file +# Write your program below + +name, age = input("Enter name and age: ").split() +age = int(age) + +print(f"Hello {name}! You are {age:d} years old.") diff --git a/Exercises/Data Types and Variables/task2.py b/Exercises/Data Types and Variables/task2.py index e8841d2..ce43c2d 100644 --- a/Exercises/Data Types and Variables/task2.py +++ b/Exercises/Data Types and Variables/task2.py @@ -1,3 +1,12 @@ +#!/usr/bin/python3 + # Write a Python program that calculates the area of a rectangle. The program should ask the user to enter # the length and width of the rectangle, and then print the area. -# Write your program below \ No newline at end of file +# Write your program below + +length = float(input("Enter Length: ")) +width = float(input("Enter Width: ")) + +area = length * width + +print(f"Area of rectangle with width {width} and length {length} is {area}") diff --git a/Exercises/Data Types and Variables/task3.py b/Exercises/Data Types and Variables/task3.py index 0c53c20..2ca3062 100644 --- a/Exercises/Data Types and Variables/task3.py +++ b/Exercises/Data Types and Variables/task3.py @@ -1,4 +1,13 @@ +#!/usr/bin/python3 + # Write a Python program that converts Fahrenheit temperatures to Celsius temperatures. # The program should ask the user to enter a temperature in Fahrenheit,and then print the # equivalent temperature in Celsius.The conversion formula is: C = (F - 32) * 5/9 -# write your program below \ No newline at end of file +# write your program below + +fah_val = float(input("Temperature (Fahrenheit value): ")) + +cel_val = (fah_val - 32) * 5/9 + +print(f"The Celcius equivalent of {fah_val}°F is {cel_val:.2f}°C") + diff --git a/Exercises/Modules/task1.py b/Exercises/Modules/task1.py deleted file mode 100644 index 0aa8da2..0000000 --- a/Exercises/Modules/task1.py +++ /dev/null @@ -1,4 +0,0 @@ -# Write a program that imports the time module and uses the sleep function to pause for 3 seconds -# before printing "Wake up!" to the console. - -# Write your program below \ No newline at end of file diff --git a/Exercises/Modules/task2.py b/Exercises/Modules/task2.py deleted file mode 100644 index 05637c6..0000000 --- a/Exercises/Modules/task2.py +++ /dev/null @@ -1,5 +0,0 @@ -# Write a program that imports the random module and uses the randrange function to generate a random integer -# between 1 and 100 (inclusive). Then, ask the user to guess the number andgive them feedback on whether their -# guess was too high, too low, or correct. - -# Write your program below \ No newline at end of file diff --git a/Exercises/Modules/task3.py b/Exercises/Modules/task3.py deleted file mode 100644 index 25ba67b..0000000 --- a/Exercises/Modules/task3.py +++ /dev/null @@ -1,6 +0,0 @@ -# Write a program that defines a function called calculate_distance that takes two sets -# of coordinates (x1, y1) and (x2, y2) as arguments and calculates the Euclidean distance -# between them using the math module. Then, ask the user to input the coordinates of two -# points and print the distance between them. - -# Write your program below \ No newline at end of file diff --git a/Exercises/Modules/task4.py b/Exercises/Modules/task4.py deleted file mode 100644 index 7b7d363..0000000 --- a/Exercises/Modules/task4.py +++ /dev/null @@ -1,5 +0,0 @@ -# Write a program that defines a function called reverse_string that takes a string as an argument and -# returns the reversed string using the reversed function from the builtins module. Then, ask the user -# to input a string and print the reversed string. - -# Write your program below \ No newline at end of file diff --git a/Exercises/Operators/task1.py b/Exercises/Operators/task1.py index 8d8ecc0..666cd5f 100644 --- a/Exercises/Operators/task1.py +++ b/Exercises/Operators/task1.py @@ -1,2 +1,14 @@ +#!/usr/bin/python3 + # Write a Python program that calculates the sum and product of two numbers entered by the user. -# Write your program below \ No newline at end of file +# Write your program below + +first, second = input(" Enter two numbers: ").split() +first = int(first) +second = int(second) +summ = first + second +prod = first * second +print("{0} and {1}. " \ + "Their sum is {2} and their product" \ + " is {3}".format(first, second, summ, prod)) + diff --git a/Exercises/Operators/task2.py b/Exercises/Operators/task2.py index 15ecbde..67077f9 100644 --- a/Exercises/Operators/task2.py +++ b/Exercises/Operators/task2.py @@ -1,2 +1,6 @@ +#!/usr/bin/python3 + # Write a Python program that checks whether a number entered by the user is even or odd. -# Write your program below \ No newline at end of file +# Write your program below + +print("{}".format(True if int(input("Number: ")) % 2 == 0 else False)) diff --git a/Exercises/Operators/task3.py b/Exercises/Operators/task3.py index ad49f03..f47676e 100644 --- a/Exercises/Operators/task3.py +++ b/Exercises/Operators/task3.py @@ -1,3 +1,12 @@ +#!/usr/bin/python3 +from math import pi as PI + # Write a Python program that calculates the area of a circle. The program should ask the user to enter # the radius of the circle, and then print the area. The value of pi can be approximated as 3.14. -# Write your program below \ No newline at end of file +# Write your program below + +radi = 0 +area = 0 +radi = int(input("Radius: ")) +area = PI * (radi ** 2) +print(f"Area of Circle with radius of {radi} = {area:.2f}") From a107593dc56efdbfd40e68d3a4f1cb25827a56f6 Mon Sep 17 00:00:00 2001 From: Dukeson Ehigboria O Date: Tue, 14 Mar 2023 18:23:29 +0100 Subject: [PATCH 02/11] Some new tasks --- Exercises/Advanced Tasks/Ballpark-orders.py | 19 +++++++++++++++ Exercises/Advanced Tasks/halloween-candy.py | 20 ++++++++++++++++ .../Advanced Tasks/new-drivers-license.py | 22 ++++++++++++++++++ Exercises/Advanced Tasks/pig-latin.py | 15 ++++++++++++ .../Advanced Tasks/safety-deposit-boxes.py | 23 +++++++++++++++++++ Exercises/Conditional Statements/task1.py | 2 ++ Exercises/Conditional Statements/task2.py | 2 ++ Exercises/Conditional Statements/task3.py | 2 ++ Exercises/Conditional Statements/task4.py | 2 ++ Exercises/Conditional Statements/task5.py | 2 ++ Exercises/Modules/task1.py | 4 ++++ Exercises/Modules/task2.py | 5 ++++ Exercises/Modules/task3.py | 6 +++++ Exercises/Modules/task4.py | 5 ++++ 14 files changed, 129 insertions(+) create mode 100644 Exercises/Advanced Tasks/Ballpark-orders.py create mode 100644 Exercises/Advanced Tasks/halloween-candy.py create mode 100644 Exercises/Advanced Tasks/new-drivers-license.py create mode 100644 Exercises/Advanced Tasks/pig-latin.py create mode 100644 Exercises/Advanced Tasks/safety-deposit-boxes.py create mode 100644 Exercises/Conditional Statements/task1.py create mode 100644 Exercises/Conditional Statements/task2.py create mode 100644 Exercises/Conditional Statements/task3.py create mode 100644 Exercises/Conditional Statements/task4.py create mode 100644 Exercises/Conditional Statements/task5.py create mode 100644 Exercises/Modules/task1.py create mode 100644 Exercises/Modules/task2.py create mode 100644 Exercises/Modules/task3.py create mode 100644 Exercises/Modules/task4.py diff --git a/Exercises/Advanced Tasks/Ballpark-orders.py b/Exercises/Advanced Tasks/Ballpark-orders.py new file mode 100644 index 0000000..a7c9249 --- /dev/null +++ b/Exercises/Advanced Tasks/Ballpark-orders.py @@ -0,0 +1,19 @@ +# You and three friends go to a baseball game and you offer to go to the concession stand for everyone. +# They each order one thing, and you do as well. Nachos and Pizza both cost $6.00. A Cheeseburger meal costs $10. +# Water is $4.00 and Coke is $5.00. Tax is 7%. + +# Task +# Determine the total cost of ordering four items from the concession stand. If one of your friend’s orders +# something that isn't on the menu, you will order a Coke for them instead. + +# Input Format +# You are given a string of the four items that you've been asked to order that are separated by spaces. + +# Output Format +# You will output a number of the total cost of the food and drinks. + +# Sample Input +# 'Pizza Cheeseburger Water Popcorn' + +# Sample Output +# 26.75 \ No newline at end of file diff --git a/Exercises/Advanced Tasks/halloween-candy.py b/Exercises/Advanced Tasks/halloween-candy.py new file mode 100644 index 0000000..af69fa9 --- /dev/null +++ b/Exercises/Advanced Tasks/halloween-candy.py @@ -0,0 +1,20 @@ +# You go trick or treating with a friend and all but three of the houses that you visit are giving out candy. +# One house that you visit is giving out toothbrushes and two houses are giving out dollar bills. + +# Task +# Given the input of the total number of houses that you visited, what is the percentage chance that one +# random item pulled from your bag is a dollar bill? + +# Input Format +# An integer (>=3) representing the total number of houses that you visited. + +# Output Format +# A percentage value rounded up to the nearest whole number. + +# Sample Input +# 4 + +# Sample Output +# 50 + +# Write your program below \ No newline at end of file diff --git a/Exercises/Advanced Tasks/new-drivers-license.py b/Exercises/Advanced Tasks/new-drivers-license.py new file mode 100644 index 0000000..63635d1 --- /dev/null +++ b/Exercises/Advanced Tasks/new-drivers-license.py @@ -0,0 +1,22 @@ +# You have to get a new driver's license and you show up at the office at the same time as 4 other people. +# The office says that they will see everyone in alphabetical order and it takes 20 minutes for them to process +# each new license. All of the agents are available now, and they can each see one customer at a time. +# How long will it take for you to walk out of the office with your new license? + +# Task +# Given everyone's name that showed up at the same time, determine how long it will take to get your new license. + +# Input Format +# Your input will be a string of your name, then an integer of the number of available agents, and lastly a string of +# the other four names separated by spaces. + +# Output Format +# You will output an integer of the number of minutes that it will take to get your license. + +# Sample Input +# 'Eric' +# 2 +# 'Adam Caroline Rebecca Frank' + +# Sample Output +# 40 \ No newline at end of file diff --git a/Exercises/Advanced Tasks/pig-latin.py b/Exercises/Advanced Tasks/pig-latin.py new file mode 100644 index 0000000..9415ce3 --- /dev/null +++ b/Exercises/Advanced Tasks/pig-latin.py @@ -0,0 +1,15 @@ +# You have two friends who are speaking Pig Latin to each other! Pig Latin is the same words in +# the same order except that you take the first letter of each word and put it on the end, then you +# add 'ay' to the end of that. ("road" = "oadray") +# Task +# Your task is to take a sentence in English and turn it into the same sentence in Pig Latin! +# Input Format +# A string of the sentence in English that you need to translate into Pig Latin. (no punctuation or capitalization) +# Output Format +# A string of the same sentence in Pig Latin. +# Sample Input +# "nevermind youve got them" +# Sample Output +# "evermindnay ouveyay otgay hemtay + +# Write your program below \ No newline at end of file diff --git a/Exercises/Advanced Tasks/safety-deposit-boxes.py b/Exercises/Advanced Tasks/safety-deposit-boxes.py new file mode 100644 index 0000000..8010d66 --- /dev/null +++ b/Exercises/Advanced Tasks/safety-deposit-boxes.py @@ -0,0 +1,23 @@ +# You are robbing a bank, but you’re not taking everything. You are looking for a specific item in +# the safety deposit boxes and you are going to drill into each one in order to find your item. +# Once you find your item you can make your escape, but how long will it take you to get to that item? + +# Task +# Determine the amount of time it will take you to find the item you are looking for if it takes you 5 +# minutes to drill into each box. + +# Input Format +# A string that represent the items in each box that will be drilled in order (items are separated by a comma), +# and secondly, a string of which item you are looking for. + +# Output Format +# An integer of the amount of time it will take for you to find your item. + +# Sample Input +# 'gold,diamonds,documents,Declaration of Independence,keys' +# 'Declaration of Independence' + +# Sample Output +# 20 + +# Write your program below \ No newline at end of file diff --git a/Exercises/Conditional Statements/task1.py b/Exercises/Conditional Statements/task1.py new file mode 100644 index 0000000..6bb4ffa --- /dev/null +++ b/Exercises/Conditional Statements/task1.py @@ -0,0 +1,2 @@ +# Write a program that takes an integer as input and prints whether it is positive, negative, or zero. +# Write your program below \ No newline at end of file diff --git a/Exercises/Conditional Statements/task2.py b/Exercises/Conditional Statements/task2.py new file mode 100644 index 0000000..53c1fb6 --- /dev/null +++ b/Exercises/Conditional Statements/task2.py @@ -0,0 +1,2 @@ +# Write a program that takes two integers as input and prints the larger one. +# Write your program below \ No newline at end of file diff --git a/Exercises/Conditional Statements/task3.py b/Exercises/Conditional Statements/task3.py new file mode 100644 index 0000000..4d0659e --- /dev/null +++ b/Exercises/Conditional Statements/task3.py @@ -0,0 +1,2 @@ +# Write a program that takes a string as input and prints whether it contains the letter "a". +# Write your program below \ No newline at end of file diff --git a/Exercises/Conditional Statements/task4.py b/Exercises/Conditional Statements/task4.py new file mode 100644 index 0000000..13771cb --- /dev/null +++ b/Exercises/Conditional Statements/task4.py @@ -0,0 +1,2 @@ +# Write a program that takes a year as input and prints whether it is a leap year or not. +# Write your program below \ No newline at end of file diff --git a/Exercises/Conditional Statements/task5.py b/Exercises/Conditional Statements/task5.py new file mode 100644 index 0000000..eac52f6 --- /dev/null +++ b/Exercises/Conditional Statements/task5.py @@ -0,0 +1,2 @@ +# Write a program that takes a number as input and prints whether it is odd or even. +# Write your program below \ No newline at end of file diff --git a/Exercises/Modules/task1.py b/Exercises/Modules/task1.py new file mode 100644 index 0000000..0aa8da2 --- /dev/null +++ b/Exercises/Modules/task1.py @@ -0,0 +1,4 @@ +# Write a program that imports the time module and uses the sleep function to pause for 3 seconds +# before printing "Wake up!" to the console. + +# Write your program below \ No newline at end of file diff --git a/Exercises/Modules/task2.py b/Exercises/Modules/task2.py new file mode 100644 index 0000000..05637c6 --- /dev/null +++ b/Exercises/Modules/task2.py @@ -0,0 +1,5 @@ +# Write a program that imports the random module and uses the randrange function to generate a random integer +# between 1 and 100 (inclusive). Then, ask the user to guess the number andgive them feedback on whether their +# guess was too high, too low, or correct. + +# Write your program below \ No newline at end of file diff --git a/Exercises/Modules/task3.py b/Exercises/Modules/task3.py new file mode 100644 index 0000000..25ba67b --- /dev/null +++ b/Exercises/Modules/task3.py @@ -0,0 +1,6 @@ +# Write a program that defines a function called calculate_distance that takes two sets +# of coordinates (x1, y1) and (x2, y2) as arguments and calculates the Euclidean distance +# between them using the math module. Then, ask the user to input the coordinates of two +# points and print the distance between them. + +# Write your program below \ No newline at end of file diff --git a/Exercises/Modules/task4.py b/Exercises/Modules/task4.py new file mode 100644 index 0000000..7b7d363 --- /dev/null +++ b/Exercises/Modules/task4.py @@ -0,0 +1,5 @@ +# Write a program that defines a function called reverse_string that takes a string as an argument and +# returns the reversed string using the reversed function from the builtins module. Then, ask the user +# to input a string and print the reversed string. + +# Write your program below \ No newline at end of file From df47c05680ddaffd559b9cef66fb06b1286d5e08 Mon Sep 17 00:00:00 2001 From: Sampul-CodeMine Date: Wed, 15 Mar 2023 00:04:09 +0100 Subject: [PATCH 03/11] Solution to Module tasks --- Exercises/Modules/task1.py | 10 ++++++++- Exercises/Modules/task2.py | 42 +++++++++++++++++++++++++++++++++++++- Exercises/Modules/task3.py | 34 +++++++++++++++++++++++++++++- Exercises/Modules/task4.py | 14 ++++++++++++- 4 files changed, 96 insertions(+), 4 deletions(-) mode change 100644 => 100755 Exercises/Modules/task1.py mode change 100644 => 100755 Exercises/Modules/task2.py mode change 100644 => 100755 Exercises/Modules/task3.py mode change 100644 => 100755 Exercises/Modules/task4.py diff --git a/Exercises/Modules/task1.py b/Exercises/Modules/task1.py old mode 100644 new mode 100755 index 0aa8da2..56e8c35 --- a/Exercises/Modules/task1.py +++ b/Exercises/Modules/task1.py @@ -1,4 +1,12 @@ +#!/usr/bin/python3 + # Write a program that imports the time module and uses the sleep function to pause for 3 seconds # before printing "Wake up!" to the console. -# Write your program below \ No newline at end of file +# Write your program below + +if __name__ == "__main__": + import time + + time.sleep(3) + print("Wake up!") diff --git a/Exercises/Modules/task2.py b/Exercises/Modules/task2.py old mode 100644 new mode 100755 index 05637c6..f93e0b0 --- a/Exercises/Modules/task2.py +++ b/Exercises/Modules/task2.py @@ -1,5 +1,45 @@ +#!/usr/bin/python3 + # Write a program that imports the random module and uses the randrange function to generate a random integer # between 1 and 100 (inclusive). Then, ask the user to guess the number andgive them feedback on whether their # guess was too high, too low, or correct. -# Write your program below \ No newline at end of file +# Write your program below + +import random + +g_range = random.randint(1, 100) +is_found = False +counter = 0 + +while is_found is False: + while True: + num_val = input("Guess Number: ( {} - {} ) ".format(1, 100)) + counter += 1 + if num_val.isnumeric(): + num_val = int(num_val) + if num_val > g_range: + is_found = False + print("{} is bigger than the number to guess.".format(num_val)) + continue + elif num_val < g_range: + is_found = False + print("{} is smaller than the number to guess.".format(num_val)) + continue + else: + is_found = True + break + + else: + is_found = False + print("Must be numeric data.") + continue + + +if is_found is True and counter <= 5: + print("You are a genius. You found the number to guess '{}' after {} guesses.".format(g_range, counter)) +elif is_found is True and counter <=10: + print("Nice work. You found the number to guess '{}' after {} guesses.".format(g_range, counter)) +else: + print("You found the number to guess {} after {} guesses. Your attempt was poor.".format(g_range, counter)) +exit(0) diff --git a/Exercises/Modules/task3.py b/Exercises/Modules/task3.py old mode 100644 new mode 100755 index 25ba67b..9b99532 --- a/Exercises/Modules/task3.py +++ b/Exercises/Modules/task3.py @@ -1,6 +1,38 @@ +#!/usr/bin/python3 + # Write a program that defines a function called calculate_distance that takes two sets # of coordinates (x1, y1) and (x2, y2) as arguments and calculates the Euclidean distance # between them using the math module. Then, ask the user to input the coordinates of two # points and print the distance between them. -# Write your program below \ No newline at end of file +# Write your program below +from math import sqrt + +def euc_distance(pt1=[], pt2=[]): + if pt1 is None or pt2 is None: + return + distance = sqrt((pt2[0] - pt1[0])**2 + (pt2[1] - pt1[1])**2) + return (distance) + +def accept(char): + data = 0 + while True: + try: + data = int(input("Enter Point {}: ".format(char))) + return (data) + except: + print("Numeric data required.") + return (0) + +row1 = [] +row2 = [] +for i in range(2): + row1.append(accept("X" + str(i + 1))) + row2.append(accept("Y" + str(i + 1))) +row1[1], row2[0] = row2[0], row1[1] +distance = euc_distance(row1, row2) +result = """ +The Euclidean distance from point {} to point {} is {:.4f} +""" +print(result.format(row1, row2, distance)) + diff --git a/Exercises/Modules/task4.py b/Exercises/Modules/task4.py old mode 100644 new mode 100755 index 7b7d363..7f34b49 --- a/Exercises/Modules/task4.py +++ b/Exercises/Modules/task4.py @@ -1,5 +1,17 @@ +#!/usr/bin/python3 + # Write a program that defines a function called reverse_string that takes a string as an argument and # returns the reversed string using the reversed function from the builtins module. Then, ask the user # to input a string and print the reversed string. -# Write your program below \ No newline at end of file +# Write your program below + +def reverse_string(strchr): + if strchr == "": + return + strchr = "".join(reversed(strchr)) + return (strchr) + +myinput = input("Enter a word or sentence: ") +print("Original String:\n{}\n".format(myinput)) +print("\nReversed String:\n{}".format(reverse_string(myinput))) From 3e970c12898676d2b912425e298402194b5f33a1 Mon Sep 17 00:00:00 2001 From: Sampul-CodeMine Date: Wed, 15 Mar 2023 01:26:56 +0100 Subject: [PATCH 04/11] Solution to Conditional Statement --- Exercises/Conditional Statements/task1.py | 12 +++++++++++- Exercises/Conditional Statements/task2.py | 14 +++++++++++++- Exercises/Conditional Statements/task3.py | 8 +++++++- Exercises/Conditional Statements/task4.py | 14 +++++++++++++- Exercises/Conditional Statements/task5.py | 10 +++++++++- 5 files changed, 53 insertions(+), 5 deletions(-) mode change 100644 => 100755 Exercises/Conditional Statements/task1.py mode change 100644 => 100755 Exercises/Conditional Statements/task2.py mode change 100644 => 100755 Exercises/Conditional Statements/task3.py mode change 100644 => 100755 Exercises/Conditional Statements/task4.py mode change 100644 => 100755 Exercises/Conditional Statements/task5.py diff --git a/Exercises/Conditional Statements/task1.py b/Exercises/Conditional Statements/task1.py old mode 100644 new mode 100755 index 6bb4ffa..432463b --- a/Exercises/Conditional Statements/task1.py +++ b/Exercises/Conditional Statements/task1.py @@ -1,2 +1,12 @@ +#!/usr/bin/python3 + # Write a program that takes an integer as input and prints whether it is positive, negative, or zero. -# Write your program below \ No newline at end of file +# Write your program below + +num = int(input("Enter a Number:")) +if num < 0: + print("Negative number") +elif num == 0: + print("Zero is the number") +else: + print("Positive number") diff --git a/Exercises/Conditional Statements/task2.py b/Exercises/Conditional Statements/task2.py old mode 100644 new mode 100755 index 53c1fb6..497a573 --- a/Exercises/Conditional Statements/task2.py +++ b/Exercises/Conditional Statements/task2.py @@ -1,2 +1,14 @@ +#!/usr/bin/python3 + # Write a program that takes two integers as input and prints the larger one. -# Write your program below \ No newline at end of file +# Write your program below + +num1, num2 = input("Enter two numbers: ").split() +num1 = int(num1) +num2 = int(num2) +if num2 > num1: + print(f"Max of {num1:d} and {num2:d} = {num2:d}") +elif num2 == num1: + print(f"Both {num1:d} and {num2:d} are equivalent") +else: + print(f"Max of {num1:d} and {num2:d} = {num1:d}") diff --git a/Exercises/Conditional Statements/task3.py b/Exercises/Conditional Statements/task3.py old mode 100644 new mode 100755 index 4d0659e..1c34b86 --- a/Exercises/Conditional Statements/task3.py +++ b/Exercises/Conditional Statements/task3.py @@ -1,2 +1,8 @@ +#!/usr/bin/python3 + # Write a program that takes a string as input and prints whether it contains the letter "a". -# Write your program below \ No newline at end of file +# Write your program below + +strin = input("Enter String: ") +if "a" in strin: + print(f"\"{strin}\" contain the letter 'a' in it.") diff --git a/Exercises/Conditional Statements/task4.py b/Exercises/Conditional Statements/task4.py old mode 100644 new mode 100755 index 13771cb..7388569 --- a/Exercises/Conditional Statements/task4.py +++ b/Exercises/Conditional Statements/task4.py @@ -1,2 +1,14 @@ +#!/usr/bin/python3 + # Write a program that takes a year as input and prints whether it is a leap year or not. -# Write your program below \ No newline at end of file +# Write your program below +lpyr = input("Enter a year: (4 digits) ") +if len(lpyr) != 4: + print(f"{leapyear} not a valid year") +lpyr = int(lpyr) +if lpyr % 400 == 0 and lpyr % 100 == 0: + print(f"{lpyr:d} is a leap year.") +elif lpyr % 4 == 0 and lpyr % 100 != 0: + print(f"{lpyr:d} is a leap year.") +else: + print(f"{lpyr:d} is not a leap year.") diff --git a/Exercises/Conditional Statements/task5.py b/Exercises/Conditional Statements/task5.py old mode 100644 new mode 100755 index eac52f6..b035620 --- a/Exercises/Conditional Statements/task5.py +++ b/Exercises/Conditional Statements/task5.py @@ -1,2 +1,10 @@ +#!/usr/bin/python3 + # Write a program that takes a number as input and prints whether it is odd or even. -# Write your program below \ No newline at end of file +# Write your program below + +num = int(input("Enter a Number: ")) +if num % 2 == 0: + print(f"{num:d} is an even number.") +else: + print(f"{num:d} is an odd number.") From dcae3dc367d9a2c252e2a2ca0e53972588e2af90 Mon Sep 17 00:00:00 2001 From: Sampul-CodeMine Date: Thu, 16 Mar 2023 15:00:16 +0100 Subject: [PATCH 05/11] Solution to all tasks and permissions granted --- Exercises/Loops/task0.py | 19 ++++++++++++++++++- Exercises/Loops/task1.py | 0 Exercises/Loops/task2.py | 0 Exercises/Loops/task3.py | 0 Exercises/Loops/task4.py | 0 Exercises/Loops/task5.py | 0 Exercises/Loops/task6.py | 0 Exercises/Loops/task7.py | 0 Exercises/Loops/task8.py | 0 Exercises/Loops/task9.py | 0 10 files changed, 18 insertions(+), 1 deletion(-) mode change 100644 => 100755 Exercises/Loops/task0.py mode change 100644 => 100755 Exercises/Loops/task1.py mode change 100644 => 100755 Exercises/Loops/task2.py mode change 100644 => 100755 Exercises/Loops/task3.py mode change 100644 => 100755 Exercises/Loops/task4.py mode change 100644 => 100755 Exercises/Loops/task5.py mode change 100644 => 100755 Exercises/Loops/task6.py mode change 100644 => 100755 Exercises/Loops/task7.py mode change 100644 => 100755 Exercises/Loops/task8.py mode change 100644 => 100755 Exercises/Loops/task9.py diff --git a/Exercises/Loops/task0.py b/Exercises/Loops/task0.py old mode 100644 new mode 100755 index 5e09595..702ff7f --- a/Exercises/Loops/task0.py +++ b/Exercises/Loops/task0.py @@ -1,2 +1,19 @@ +#!/usr/bin/python3 + # Write a program that asks the user to enter a series of numbers and then prints out the number of even and odd numbers entered. -# Write your program below \ No newline at end of file +# Write your program below + +def acceptval(strchr): + while True: + try: + num = int(input(f"Enter {strchr}: ")) + return (num) + except: + print("Numeric value required.") + +num = [] +rng = acceptval("Range") +for i in range(rng): + num.append(acceptval("Number")) +print("{} is {}".format + diff --git a/Exercises/Loops/task1.py b/Exercises/Loops/task1.py old mode 100644 new mode 100755 diff --git a/Exercises/Loops/task2.py b/Exercises/Loops/task2.py old mode 100644 new mode 100755 diff --git a/Exercises/Loops/task3.py b/Exercises/Loops/task3.py old mode 100644 new mode 100755 diff --git a/Exercises/Loops/task4.py b/Exercises/Loops/task4.py old mode 100644 new mode 100755 diff --git a/Exercises/Loops/task5.py b/Exercises/Loops/task5.py old mode 100644 new mode 100755 diff --git a/Exercises/Loops/task6.py b/Exercises/Loops/task6.py old mode 100644 new mode 100755 diff --git a/Exercises/Loops/task7.py b/Exercises/Loops/task7.py old mode 100644 new mode 100755 diff --git a/Exercises/Loops/task8.py b/Exercises/Loops/task8.py old mode 100644 new mode 100755 diff --git a/Exercises/Loops/task9.py b/Exercises/Loops/task9.py old mode 100644 new mode 100755 From bc2e69bda7849c4caa868c43964e05c3882f85a1 Mon Sep 17 00:00:00 2001 From: Dukeson Ehigboria O Date: Thu, 16 Mar 2023 17:03:05 +0100 Subject: [PATCH 06/11] Solution to Loops --- Exercises/Loops/task0.py | 3 ++- Exercises/Loops/task1.py | 16 +++++++++++++++- Exercises/Loops/task2.py | 17 ++++++++++++++++- Exercises/Loops/task3.py | 23 +++++++++++++++++++++- Exercises/Loops/task4.py | 7 ++++++- Exercises/Loops/task5.py | 25 +++++++++++++++++++++++- Exercises/Loops/task6.py | 41 +++++++++++++++++++++++++++++++++++++++- Exercises/Loops/task7.py | 14 +++++++++++++- Exercises/Loops/task8.py | 12 +++++++++++- Exercises/Loops/task9.py | 16 +++++++++++++++- 10 files changed, 164 insertions(+), 10 deletions(-) diff --git a/Exercises/Loops/task0.py b/Exercises/Loops/task0.py index 702ff7f..01277ba 100755 --- a/Exercises/Loops/task0.py +++ b/Exercises/Loops/task0.py @@ -15,5 +15,6 @@ def acceptval(strchr): rng = acceptval("Range") for i in range(rng): num.append(acceptval("Number")) -print("{} is {}".format +for n in num: + print("{} is {}".format(n, ("Even" if n % 2 == 0 else "Odd"))) diff --git a/Exercises/Loops/task1.py b/Exercises/Loops/task1.py index 0d6f202..ae0b13d 100755 --- a/Exercises/Loops/task1.py +++ b/Exercises/Loops/task1.py @@ -1,3 +1,17 @@ +#!/usr/bin/python3 + # Write a program that prints all the numbers from 1 to 100. For multiples of 3, print "Fizz" instead of the number. # For multiples of 5, print "Buzz" instead of the number. For multiples of both 3 and 5, print "FizzBuzz" instead of the number. -# Write your program below \ No newline at end of file +# Write your program below +for i in range(1, 101): + if i == 100: + print("{}".format(i), end="") + break + if i % 15 == 0: + print("FizzBuzz", end=" ") + elif i % 3 == 0: + print("Fizz", end=" ") + elif i % 5 == 0: + print("Buzz", end=" ") + else: + print("{}".format(i), end=" ") diff --git a/Exercises/Loops/task2.py b/Exercises/Loops/task2.py index 4029237..37f26c2 100755 --- a/Exercises/Loops/task2.py +++ b/Exercises/Loops/task2.py @@ -1,2 +1,17 @@ +#!/usr/bin/ptyhon3 + # Write a program that asks the user to input a number and then prints the multiplication table for that number up to 10. -# Write your program below \ No newline at end of file +# Write your program below +num = 0 +while True: + try: + num = int(input("Enter a Number: ")) + break + except ValueError: + print("Numeric data required.") + +for i in range(1, (num + 1)): + print(f"=== {i} Times Table ===") + for j in range(1, 11): + print("{:d} * {:d} = {:d}".format(i, j, (i * j))) + print() diff --git a/Exercises/Loops/task3.py b/Exercises/Loops/task3.py index 3ca2928..dc733e2 100755 --- a/Exercises/Loops/task3.py +++ b/Exercises/Loops/task3.py @@ -1,2 +1,23 @@ +#!/usr/bin/python3 + # Write a program that asks the user to input a series of numbers and then calculates the average of those numbers. -# Write your progam below \ No newline at end of file +# Write your program below + +if __name__ == "__main__": + import sys as s + + total = 0 # the sum of all values + arg_count = len(s.argv) - 1 # number of arguments passed + if arg_count == 0: + print("Enter series of numbers separated with comma") + n_temp = list(input().split()) + for n in n_temp: + total += int(n) + print("The sum of {} = {}".format(n_temp, total)) + exit(0) + else: + nums = [] + for num in range(arg_count): + total += num + nums.append(num) + print("The sum of {} = {}".format(nums, total)) diff --git a/Exercises/Loops/task4.py b/Exercises/Loops/task4.py index c00f603..0147c1c 100755 --- a/Exercises/Loops/task4.py +++ b/Exercises/Loops/task4.py @@ -1,2 +1,7 @@ +#!/usr/bin/python3 + # Write a program that asks the user to input a string and then prints out each character in the string on a new line. -# Write your program below \ No newline at end of file +# Write your program below +strchr = input("Enter a String: ") +for st in strchr: + print(st) diff --git a/Exercises/Loops/task5.py b/Exercises/Loops/task5.py index fc89d4b..9b2a1fb 100755 --- a/Exercises/Loops/task5.py +++ b/Exercises/Loops/task5.py @@ -1,2 +1,25 @@ +#!/usr/bin/python3 + # Write a program that uses a loop to find the largest number in a list of numbers entered by the user. -# Write your program below \ No newline at end of file +# Write your program below +def accept_val(strchr): + while True: + try: + numbe = int(input("Enter {}: ".format(strchr))) + return numbe + except ValueError: + print("Please provide a numeric data") + + +numb = [] +res = 'y' +while True: + numb.append(accept_val("Number")) + res = input("More numbers (y/n)? ") + if res not in 'Yy': + break +largest = numb[0] +for i in range(1, len(numb)): + if largest < numb[i]: + largest = numb[i] +print("The largest value in {} is {}".format(numb, largest)) diff --git a/Exercises/Loops/task6.py b/Exercises/Loops/task6.py index 1043d1c..cfc291e 100755 --- a/Exercises/Loops/task6.py +++ b/Exercises/Loops/task6.py @@ -1,4 +1,43 @@ +#!/usr/bin/python3 # Write a program that generates a random number between 1 and 100 and asks the user to guess the number. # The program should keep asking the user to guess until they get the number right, and then print out # the number of guesses it took. -# Write your program below \ No newline at end of file +# Write your program below + +import random + +g_range = random.randint(1, 100) +is_found = False +counter = 0 + +while is_found is False: + while True: + num_val = input("Guess Number: ( {} - {} ) ".format(1, 100)) + counter += 1 + if num_val.isnumeric(): + num_val = int(num_val) + if num_val > g_range: + is_found = False + print("{} is bigger than the number to guess.".format(num_val)) + continue + elif num_val < g_range: + is_found = False + print("{} is smaller than the number to guess.".format(num_val)) + continue + else: + is_found = True + break + + else: + is_found = False + print("Must be numeric data.") + continue + + +if is_found is True and counter <= 5: + print("You are a genius. You found the number to guess '{}' after {} guesses.".format(g_range, counter)) +elif is_found is True and counter <=10: + print("Nice work. You found the number to guess '{}' after {} guesses.".format(g_range, counter)) +else: + print("You found the number to guess {} after {} guesses. Your attempt was poor.".format(g_range, counter)) +exit(0) \ No newline at end of file diff --git a/Exercises/Loops/task7.py b/Exercises/Loops/task7.py index f9ee2bc..10a34f0 100755 --- a/Exercises/Loops/task7.py +++ b/Exercises/Loops/task7.py @@ -1,2 +1,14 @@ +#!/usr/bin/python3 + # Write a program that asks the user to enter a series of words and then prints out the words in alphabetical order. -# Write your program below \ No newline at end of file +# Write your program below +strlist = [] +res = 'y' +while True: + strlist.append(input("Word: ")) + res = input("More words (y/n)? ") + if res not in 'Yy': + break +strlist.sort() +for st in strlist: + print(st) diff --git a/Exercises/Loops/task8.py b/Exercises/Loops/task8.py index 3ab179b..502436b 100755 --- a/Exercises/Loops/task8.py +++ b/Exercises/Loops/task8.py @@ -1,2 +1,12 @@ +#!/usr/bin/python3 + # Write a program that asks the user to enter a sentence and then counts the number of vowels (a, e, i, o, u) in the sentence. -# Write your program below \ No newline at end of file +# Write your program below + +user_input = input("Enter a Sentence: ") +counter = 0 +for ui in user_input: + if ui in "aeiou": + counter += 1 +print("The number of vowels (a, e, i, o, u) in the " \ + "sentence:\n\"{}\"\nis = {}".format(user_input, counter)) diff --git a/Exercises/Loops/task9.py b/Exercises/Loops/task9.py index 7293be4..c145dbb 100755 --- a/Exercises/Loops/task9.py +++ b/Exercises/Loops/task9.py @@ -1,2 +1,16 @@ +#!/usr/bin/python3 + # Write a program that uses a loop to print out the first 10 Fibonacci numbers. -# Write your program below \ No newline at end of file +# Write your program below + +first_val = 0 +second_val = 1 +for i in range(11): + if i <= 1: + fib = i + else: + fib = first_val + second_val + # first_val = second_val + # second_val = fib + first_val, second_val = second_val, fib +print(fib) \ No newline at end of file From f8de69e1583cc14b1cbbf6be1854eb5c114cb3b7 Mon Sep 17 00:00:00 2001 From: Dukeson Ehigboria O Date: Fri, 17 Mar 2023 22:33:29 +0100 Subject: [PATCH 07/11] Solution to List tasks --- Exercises/Lists/task0.py | 9 ++++++++- Exercises/Lists/task1.py | 10 +++++++++- Exercises/Lists/task2.py | 13 ++++++++++++- Exercises/Lists/task3.py | 12 +++++++++++- Exercises/Lists/task4.py | 14 +++++++++++++- Exercises/Lists/task5.py | 12 +++++++++++- Exercises/Lists/task6.py | 9 ++++++++- Exercises/Lists/task7.py | 9 ++++++++- Exercises/Lists/task8.py | 8 +++++++- Exercises/Lists/task9.py | 26 +++++++++++++++++++++++++- 10 files changed, 112 insertions(+), 10 deletions(-) diff --git a/Exercises/Lists/task0.py b/Exercises/Lists/task0.py index 92ceead..80b39cd 100644 --- a/Exercises/Lists/task0.py +++ b/Exercises/Lists/task0.py @@ -1,2 +1,9 @@ +#!/usr/bin/python3 + # Write a Python program to reverse a list. -# Write your program below \ No newline at end of file +# Write your program below +new_list = [] +num_list = [21, 201, 54, 66, 100, -1000, 43, 200] +for i in num_list[::-1]: + new_list.append(i) +print(new_list) diff --git a/Exercises/Lists/task1.py b/Exercises/Lists/task1.py index 848062d..0aeb22f 100644 --- a/Exercises/Lists/task1.py +++ b/Exercises/Lists/task1.py @@ -1,2 +1,10 @@ +#!/usr/bin/python3 + # Write a Python program to find the sum of all the elements in a list. -# Write your program below \ No newline at end of file +# Write your program below + +num_list = [21, 201, 54, 66, 100, -1000, 43, 200] +total = 0 +for n in num_list: + total += n +print("The sum of elements in {} = {}".format(num_list, total)) diff --git a/Exercises/Lists/task2.py b/Exercises/Lists/task2.py index e48efc3..f326c16 100644 --- a/Exercises/Lists/task2.py +++ b/Exercises/Lists/task2.py @@ -1,2 +1,13 @@ +#!/usr/bin/python3 + # Write a Python program to find the largest number in a list. -# Write your program below \ No newline at end of file +# Write your program below + +num_list = [21, 201, 54, 66, 100, -1000, 43, 200] + +large = num_list[0] +for n in range(1, len(num_list)): + if num_list[n] > large: + large = num_list[n] + +print(f"The largest number in the list: {num_list} = {large}") diff --git a/Exercises/Lists/task3.py b/Exercises/Lists/task3.py index 54d8de7..b3c5f39 100644 --- a/Exercises/Lists/task3.py +++ b/Exercises/Lists/task3.py @@ -1,2 +1,12 @@ +#!/usr/bin/python3 + # Write a Python program to remove duplicates from a list. -# Write your program below \ No newline at end of file +# Write your program below + +num_list = [21, 201, 54, 66, 100, -100, 201, 200, 55, 54, 43, 200] +print("Initial List: {}".format(num_list)) + +temp = set(num_list) + +num_list = list(temp) +print("New List: {}".format(num_list)) diff --git a/Exercises/Lists/task4.py b/Exercises/Lists/task4.py index a77ec17..3e4b603 100644 --- a/Exercises/Lists/task4.py +++ b/Exercises/Lists/task4.py @@ -1,2 +1,14 @@ +#!/usr/bin/python3 + # Write a Python program to concatenate two lists. -# Write your program below \ No newline at end of file +# Write your program below + +num_list = [21, 201, 54, 66, 100, -1000, 43, 200] +alpha_list = ["a", "e", "i", "o", "u"] + +new_list = num_list + alpha_list + +print("Using a new list to concatenate: {}".format(new_list)) + +num_list.extend(alpha_list) +print("Using the Extend function: {}".format(num_list)) diff --git a/Exercises/Lists/task5.py b/Exercises/Lists/task5.py index 040224b..313fed6 100644 --- a/Exercises/Lists/task5.py +++ b/Exercises/Lists/task5.py @@ -1,2 +1,12 @@ +#!/usr/bin/python3 + # Write a Python program to check if a given element exists in a list. -# Write your program below \ No newline at end of file +# Write your program below + +lists = [21, 201, 54, 66, 100, -1000, 43, 200, 'a', 'e', 'i', 'o', 'u'] +resp = input("Enter a number or character: ") +if resp in lists: + idx = lists.index(resp, 0, -1) + print("'{}' was found in the list: {} at index of {}".format(resp, lists, idx)) +else: + print("'{}' was NOT found in the list: {}".format(resp, lists)) diff --git a/Exercises/Lists/task6.py b/Exercises/Lists/task6.py index b5f8d92..a8556bb 100644 --- a/Exercises/Lists/task6.py +++ b/Exercises/Lists/task6.py @@ -1,2 +1,9 @@ +#!/usr/bin/python3 + # Write a Python program to find the second largest number in a list. -# Write your program below \ No newline at end of file +# Write your program below +lists = [21, 201, 54, 66, 100, -1000, 43, 200] +print(f"List is : {lists}") +lists.sort(reverse=True) +print(f"Sorted List is : {lists}", end=", ") +print(f"and the second largest number is {lists[1]}") diff --git a/Exercises/Lists/task7.py b/Exercises/Lists/task7.py index 73b0e12..1f3cf0e 100644 --- a/Exercises/Lists/task7.py +++ b/Exercises/Lists/task7.py @@ -1,2 +1,9 @@ +#!/usr/bin/python3 + # Write a Python program to sort a list of numbers in descending order. -# Write your program below \ No newline at end of file +# Write your program below + +lists = [21, 201, 54, 66, 100, -1000, 43, 200] +print("Original List: {}".format(lists)) +lists.sort(reverse=True) +print("Sorted list in descending order: {}".format(lists)) diff --git a/Exercises/Lists/task8.py b/Exercises/Lists/task8.py index 7c0a64e..d2cd353 100644 --- a/Exercises/Lists/task8.py +++ b/Exercises/Lists/task8.py @@ -1,2 +1,8 @@ +#!/usr/bin/python3 + # Write a Python program to remove the first occurrence of a given element from a list. -# Write your program below \ No newline at end of file +# Write your program below +alpha = ["a", "b", "v", "d", "a", "r"] +print(f"Original List: {alpha}") +alpha.remove("a") +print(f"Modified List: {alpha}") diff --git a/Exercises/Lists/task9.py b/Exercises/Lists/task9.py index e42b93a..52c8b0d 100644 --- a/Exercises/Lists/task9.py +++ b/Exercises/Lists/task9.py @@ -1,2 +1,26 @@ +#!/usr/bin/python3 + # Write a Python program to count the number of occurrences of a given element in a list. -# Write your program below \ No newline at end of file +# Write your program below +mylist = ["b", "a", "n", "k", "e", "r", "s", "r", "i", "g", "h", "t", "b"] + +def get_occurrence(char, lists): + if lists is None or lists == []: + return + count = 0 + for i in lists: + if char == i: + count += 1 + if count == 0: + return 0 + return count + + +data = input("What character ? ") +result = get_occurrence(data, mylist) +if result is None: + print("This list is empty") +elif result == 0: + print(f"\"{data}\" was not found in the list: {mylist}") +else: + print(f"\"{data}\" was found in the list: {mylist} {result} times.") From baa09fe529d0031c67ff62757e083ef87827d63d Mon Sep 17 00:00:00 2001 From: Dukeson Ehigboria O Date: Sat, 18 Mar 2023 10:04:58 +0100 Subject: [PATCH 08/11] Some solutions to the advanced task --- Exercises/Advanced Tasks/Ballpark-orders.py | 9 ++++++-- Exercises/Advanced Tasks/pig-latin.py | 24 ++++++++++++++++++++- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/Exercises/Advanced Tasks/Ballpark-orders.py b/Exercises/Advanced Tasks/Ballpark-orders.py index a7c9249..b7acad3 100644 --- a/Exercises/Advanced Tasks/Ballpark-orders.py +++ b/Exercises/Advanced Tasks/Ballpark-orders.py @@ -1,4 +1,6 @@ -# You and three friends go to a baseball game and you offer to go to the concession stand for everyone. +#!/usr/bin/python3 + +# You and three friends go to a baseball game. You offer to go to the concession stand for everyone. # They each order one thing, and you do as well. Nachos and Pizza both cost $6.00. A Cheeseburger meal costs $10. # Water is $4.00 and Coke is $5.00. Tax is 7%. @@ -16,4 +18,7 @@ # 'Pizza Cheeseburger Water Popcorn' # Sample Output -# 26.75 \ No newline at end of file +# 26.75 +menu = {"Nachos": 6, "Pizza": 6, "Cheeseburger": 10, "Water": 4, "Coke": 5} +tax = 7/100 +total = 0 diff --git a/Exercises/Advanced Tasks/pig-latin.py b/Exercises/Advanced Tasks/pig-latin.py index 9415ce3..d208fcd 100644 --- a/Exercises/Advanced Tasks/pig-latin.py +++ b/Exercises/Advanced Tasks/pig-latin.py @@ -1,3 +1,5 @@ +#!/usr/bin/python3 + # You have two friends who are speaking Pig Latin to each other! Pig Latin is the same words in # the same order except that you take the first letter of each word and put it on the end, then you # add 'ay' to the end of that. ("road" = "oadray") @@ -12,4 +14,24 @@ # Sample Output # "evermindnay ouveyay otgay hemtay -# Write your program below \ No newline at end of file +# Write your program belo +def converter(strchr): + if strchr == "": + return + str_list = list(strchr.split()) + final_word = [] + for ch in str_list: + word = ch[0] + new_word = [] + for c in range(1, len(ch)): + new_word.append(ch[c]) + new_word.append(word) + new_word.append("ay") + final_word.append(str("".join(new_word))) + return str(" ".join(final_word)) + + +user_str = input("Enter a Sentence: ") +new_str = converter(user_str).strip() +print(f"Original Sentence:\n\"{user_str}\"\n") +print(f"Pig Latin Sentence:\n\"{new_str}\"") From db1fe0758965e369d23c68aeb5c7164cb1f3faad Mon Sep 17 00:00:00 2001 From: Dukeson Ehigboria O Date: Sat, 18 Mar 2023 16:25:15 +0100 Subject: [PATCH 09/11] Solution to two of the advanced tasks --- .gitignore | 4 +++ .idea/.gitignore | 3 +++ .../inspectionProfiles/profiles_settings.xml | 6 +++++ .idea/misc.xml | 4 +++ .idea/modules.xml | 8 ++++++ .idea/python-tutorial.iml | 8 ++++++ .idea/vcs.xml | 6 +++++ 00-introduction.md | 1 + Exercises/Advanced Tasks/Ballpark-orders.py | 27 ++++++++++++++++++- 9 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/python-tutorial.iml create mode 100644 .idea/vcs.xml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..246f416 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.swp *.exe +*.exe +*.out +idea/* diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..a971a2c --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..ebcc356 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/python-tutorial.iml b/.idea/python-tutorial.iml new file mode 100644 index 0000000..d0876a7 --- /dev/null +++ b/.idea/python-tutorial.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/00-introduction.md b/00-introduction.md index 00fd2d0..709b15d 100644 --- a/00-introduction.md +++ b/00-introduction.md @@ -1,4 +1,5 @@ # Introduction + Python is a high-level, interpreted programming language that's known for its simplicity, readability, and versatility. It was first released in 1991 by Guido van Rossum, and has since become one of the most popular programming languages in the world. Python is widely used for a variety of applications, including web development, data analysis, machine learning, and scientific computing. One of the key features of Python is its syntax, which is designed to be easy to read and write. Python code is typically more concise and readable than code in other programming languages, which makes it a great choice for beginners who are just getting started with programming. diff --git a/Exercises/Advanced Tasks/Ballpark-orders.py b/Exercises/Advanced Tasks/Ballpark-orders.py index b7acad3..b4336bf 100644 --- a/Exercises/Advanced Tasks/Ballpark-orders.py +++ b/Exercises/Advanced Tasks/Ballpark-orders.py @@ -19,6 +19,31 @@ # Sample Output # 26.75 -menu = {"Nachos": 6, "Pizza": 6, "Cheeseburger": 10, "Water": 4, "Coke": 5} +menu = {"Nachos": 6, "Pizza": 6, "Cheeseburger": 10, "Coke": 5, "Water": 4} tax = 7/100 total = 0 +menu_keys = list(menu.keys()) +menu_vals = list(menu.values()) +order_cost = [] + +prompt = """ +Make an order: + +Available meals are: [Nachos], [Pizza], [Cheeseburger], [Coke], [Water] +Separate orders with a space each ::: """ + +orders = input(prompt).split() +for order in orders: + if order in menu: + order_cost.append(menu[order]) + else: + order_cost.append(menu["Water"]) + +for i in order_cost: + total += int(i) + +print("\nYour Orders are: {}".format(", ".join(orders))) +print("The prices are: {}".format(str(order_cost))) +print(f"The total for the items is: $ {total} and you have earned 7% discount.") +print("Your pay now is : $ {:.2f}".format(total - (total * tax))) + From 0044c1b9554bbe706b663964c77a419e3b0eb32b Mon Sep 17 00:00:00 2001 From: Dukeson Ehigboria O Date: Sat, 18 Mar 2023 16:27:01 +0100 Subject: [PATCH 10/11] Solution to two of the advanced tasks --- Exercises/.gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Exercises/.gitignore diff --git a/Exercises/.gitignore b/Exercises/.gitignore new file mode 100644 index 0000000..e42c618 --- /dev/null +++ b/Exercises/.gitignore @@ -0,0 +1,2 @@ +.idea/* +__pycache__ \ No newline at end of file From 5a6d2d98e1c7102deedbbfa5fda0e630737c7049 Mon Sep 17 00:00:00 2001 From: Dukeson Ehigboria O Date: Sat, 18 Mar 2023 16:34:41 +0100 Subject: [PATCH 11/11] Starting on the next advance task soon --- .gitignore | 3 ++- .idea/.gitignore | 3 --- .idea/inspectionProfiles/profiles_settings.xml | 6 ------ .idea/misc.xml | 4 ---- .idea/modules.xml | 8 -------- .idea/python-tutorial.iml | 8 -------- .idea/vcs.xml | 6 ------ Exercises/.gitignore | 2 -- Exercises/Advanced Tasks/halloween-candy.py | 2 ++ Exercises/Advanced Tasks/new-drivers-license.py | 2 ++ 10 files changed, 6 insertions(+), 38 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/inspectionProfiles/profiles_settings.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/python-tutorial.iml delete mode 100644 .idea/vcs.xml delete mode 100644 Exercises/.gitignore diff --git a/.gitignore b/.gitignore index 246f416..7c0b47e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.swp *.exe *.exe *.out -idea/* +.idea/* +__pycache__ \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 26d3352..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml deleted file mode 100644 index 105ce2d..0000000 --- a/.idea/inspectionProfiles/profiles_settings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index a971a2c..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index ebcc356..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/python-tutorial.iml b/.idea/python-tutorial.iml deleted file mode 100644 index d0876a7..0000000 --- a/.idea/python-tutorial.iml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/Exercises/.gitignore b/Exercises/.gitignore deleted file mode 100644 index e42c618..0000000 --- a/Exercises/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -.idea/* -__pycache__ \ No newline at end of file diff --git a/Exercises/Advanced Tasks/halloween-candy.py b/Exercises/Advanced Tasks/halloween-candy.py index af69fa9..b0afe28 100644 --- a/Exercises/Advanced Tasks/halloween-candy.py +++ b/Exercises/Advanced Tasks/halloween-candy.py @@ -1,3 +1,5 @@ +#!/usr/bin/python3 + # You go trick or treating with a friend and all but three of the houses that you visit are giving out candy. # One house that you visit is giving out toothbrushes and two houses are giving out dollar bills. diff --git a/Exercises/Advanced Tasks/new-drivers-license.py b/Exercises/Advanced Tasks/new-drivers-license.py index 63635d1..c8ceca9 100644 --- a/Exercises/Advanced Tasks/new-drivers-license.py +++ b/Exercises/Advanced Tasks/new-drivers-license.py @@ -1,3 +1,5 @@ +#!/usr/bin/python3 + # You have to get a new driver's license and you show up at the office at the same time as 4 other people. # The office says that they will see everyone in alphabetical order and it takes 20 minutes for them to process # each new license. All of the agents are available now, and they can each see one customer at a time.