diff --git a/Ch2 - Basics/challenge.py b/Ch2 - Basics/challenge.py new file mode 100644 index 0000000..2672ca1 --- /dev/null +++ b/Ch2 - Basics/challenge.py @@ -0,0 +1,23 @@ +# Palindrome - Reads a string the same way +# Characters = strings, numbers - No puctuations or spaces +# 1. Merge the entire string (Remove any puctiations, spaces) +# 2. Take input like exit from user and quit +# 3. Reverse the merged string and compare with merged screen +# 4. If same = palindrome else false +import re + +def merge_character(testchar): + new_alphanum = re.sub('[^A-Za-z0-9]+', '', testchar) + return new_alphanum +def inverse_alphanum(testchar): + new_inverse = merge_character(testchar)[::-1] + return new_inverse + +testchar = input("Enter a string to test for palindrome or \'exit\': ") +lower_testchar = testchar.lower() +if lower_testchar == "exit": + print("Bye") +elif merge_character(lower_testchar) == inverse_alphanum(lower_testchar): + print("Palindrone Test: True") +else: + print("Palindrone Test: Failed") diff --git a/Ch2 - Basics/conditionals_start.py b/Ch2 - Basics/conditionals_start.py index f6b58d6..9942cbc 100644 --- a/Ch2 - Basics/conditionals_start.py +++ b/Ch2 - Basics/conditionals_start.py @@ -6,9 +6,12 @@ def main(): - x, y = 10, 100 + x, y = 10000, 100 # conditional flow uses if, elif, else + if x < y: + result = "X is less than Y" + print(result) # conditional statements let you use "a if C else b" diff --git a/Ch2 - Basics/functions_start.py b/Ch2 - Basics/functions_start.py index 56cb247..a03b6d9 100644 --- a/Ch2 - Basics/functions_start.py +++ b/Ch2 - Basics/functions_start.py @@ -5,10 +5,12 @@ # TODO: define a basic function - +def func1(): + print("I am a function") # TODO: function that takes arguments - +def func2(arg1, arg2): + print (arg1, " ", arg2) # TODO: function that returns a value @@ -19,3 +21,6 @@ # TODO: function with variable number of arguments +func1() +print(func1()) +print (func1) \ No newline at end of file diff --git a/Ch2 - Basics/helloworld_start.py b/Ch2 - Basics/helloworld_start.py index 7d6b753..354d0a0 100644 --- a/Ch2 - Basics/helloworld_start.py +++ b/Ch2 - Basics/helloworld_start.py @@ -3,4 +3,10 @@ # LinkedIn Learning Python course by Joe Marini # +def main(): + print("Hello World") + name = input('What is your name?') + print("Nice to meet you", name) +if __name__ == "__main__": + main() diff --git a/Ch2 - Basics/variables_start.py b/Ch2 - Basics/variables_start.py index b2756cc..eecd277 100644 --- a/Ch2 - Basics/variables_start.py +++ b/Ch2 - Basics/variables_start.py @@ -13,25 +13,34 @@ mytuple = (0, 1, 2) mydict = {"one" : 1, "two" : 2} -print(myint) -print(myfloat) +#print(myint) +#print(myfloat) print(mystr) -print(mybool) -print(mylist) -print(mytuple) -print(mydict) +#print(mybool) +#print(mylist) +#print(mytuple) +#print(mydict) # re-declaring a variable works # to access a member of a sequence type, use [] # use slices to get parts of a sequence +#print(mylist[1:]) # you can use slices to reverse a sequence # dictionaries are accessed via keys +#print(mydict["one"]) # ERROR: variables of different types cannot be combined +#print("My Stinrg" + str(123)) # Global vs. local variables in functions +def locgob(): + global mystr + mystr = "def" + print(mystr) +locgob() +print(mystr) diff --git a/Ch3 - Files/challenge-files.py b/Ch3 - Files/challenge-files.py new file mode 100644 index 0000000..3acdb5f --- /dev/null +++ b/Ch3 - Files/challenge-files.py @@ -0,0 +1,20 @@ +# Crete a dir +# Open / Create a file +# run OS commands like list dir shutils? +# Close file + +import os +import subprocess + +def main(): + + directory = "results" + os.mkdir(directory) + # os.rmdir(directory) + + with open(r'' + directory + '/list.txt', 'w') as f: + subprocess.run(['find', '/"Ch3 - Files"', '-maxdepth', '1', '-type', 'f'], stdout=f) + +if __name__ == "__main__": + main() + diff --git a/Ch4 - Dates and Times/calendars_finished.py b/Ch4 - Dates and Times/calendars_finished.py index 1372384..371e32b 100644 --- a/Ch4 - Dates and Times/calendars_finished.py +++ b/Ch4 - Dates and Times/calendars_finished.py @@ -5,6 +5,7 @@ import calendar +from itertools import count # create a plain text calendar c = calendar.TextCalendar(calendar.SUNDAY) @@ -40,6 +41,7 @@ # The first Friday has to be within the first two weeks weekone = cal[0] weektwo = cal[1] + print(count(cal)) if weekone[calendar.FRIDAY] != 0: meetday = weekone[calendar.FRIDAY] diff --git a/Ch4 - Dates and Times/challenge_start.py b/Ch4 - Dates and Times/challenge_start.py index 9da42cb..6ff0df9 100644 --- a/Ch4 - Dates and Times/challenge_start.py +++ b/Ch4 - Dates and Times/challenge_start.py @@ -1,5 +1,44 @@ # Start file for programming challenge for Learning Python course # LinkedIn Learning Python course by Joe Marini -# +# 1. Print the string asking user to choose the day of the week and then the month and year for which count of the day is required +# 2. Make sure the selection is from a fixed set of strings. +# 3. Send the information to another class - where count of days is calculated +# 4. import calendar +def countdays(theyear, themonth, whichday): + daycount = 0 + weekslist = calendar.monthcalendar(theyear, themonth) + for week in weekslist: + if week[whichday] != 0: + daycount += 1 + return daycount + +run = True +while (run): + i = 0 + print("Select the day of the week or type exit to quit:") + for day in calendar.day_name: + print (i, day) + i = i+1 + weekselect = input("Your selection: ") + + lower_testchar = weekselect.lower() + if lower_testchar == "exit": + run = False + break + elif weekselect.isnumeric() == False or int(weekselect) > i: + print("Please add a valid number") + else: + useryear = int(input("Enter year: ")) + usermonth = int(input("Enter month: ")) + #userday = calendar.day_name[int(weekselect)] + userday = int(weekselect) + print(userday) + result = countdays(useryear, usermonth, userday) + + print("There are "+ str(result) +" in the month of specified year.") + # i = calendar.weekday(useryear, usermonth, int(weekselect)-1) + # print (i) + + diff --git a/results/list.txt b/results/list.txt new file mode 100644 index 0000000..e69de29