diff --git a/python/lp3thw/Exercise12/ex12.py b/python/lp3thw/Exercise12/ex12.py index 8ca35aa..2878048 100644 --- a/python/lp3thw/Exercise12/ex12.py +++ b/python/lp3thw/Exercise12/ex12.py @@ -1,6 +1,6 @@ age = input("How old are you? ") -height = input("How tall are you?") -weight = input("How much do you weight?") +height = input("How tall are you? ") +weight = input("How much do you weight? ") print(f"So, you're {age} old, {height} tall, and {weight} heavy/") \ No newline at end of file diff --git a/python/lp3thw/Exercise13/ex13.py b/python/lp3thw/Exercise13/ex13.py new file mode 100644 index 0000000..fc321dc --- /dev/null +++ b/python/lp3thw/Exercise13/ex13.py @@ -0,0 +1,9 @@ +from sys import argv + +script, first, second, third = argv + +print("The script is called: ", script) +print(f"The first variable was: {first}") +print(f"The second variable was: {second}\nThe third variable was : {third}") + +#To run this script you must call it from the terminal via - python ex13.py Arg1 Arg2 Arg3 \ No newline at end of file diff --git a/python/lp3thw/Exercise14/ex14.py b/python/lp3thw/Exercise14/ex14.py new file mode 100644 index 0000000..192cfa6 --- /dev/null +++ b/python/lp3thw/Exercise14/ex14.py @@ -0,0 +1,21 @@ +#!/bin/python3 + +from sys import argv + +script, userName, likeLevel = argv +prompt = "Well? - " + +print(f"Hi {userName}, I'm the {script} script") +print("I'd like to ask you a few questions: ") +print(f"Do you like me {userName}") +likes = input(prompt) +print(f"Where you live {userName}?") +lives = input(prompt) +print(f"What kind of Computer do you have?") +computer = input(prompt) +print(f""" +Alright, so you said {likes} about liking me. +Your likeness level was {likeLevel}. What did i do? +You reside in {lives}. Where is that exactly? +And you have a {computer} computer. +""") \ No newline at end of file diff --git a/python/lp3thw/Exercise15/ex15.py b/python/lp3thw/Exercise15/ex15.py new file mode 100644 index 0000000..f7c218f --- /dev/null +++ b/python/lp3thw/Exercise15/ex15.py @@ -0,0 +1,18 @@ +from sys import argv + +script, filename = argv + +txt = open(filename) + +print(f"Here's your file {filename}") +print(txt.read()) + +print("Type the filename again: ") +fileAgain = input("> ") + +txtAgain = open(fileAgain) + +print(txtAgain.read()) +#It seems that you can only have one active file stream open at a time. So in order to print the txt variable, we would need to redefine it. +#txt = open(filename) +#print(txt.read()) diff --git a/python/lp3thw/Exercise16/ex16.py b/python/lp3thw/Exercise16/ex16.py new file mode 100644 index 0000000..ac816dd --- /dev/null +++ b/python/lp3thw/Exercise16/ex16.py @@ -0,0 +1,35 @@ +from sys import argv + +script, filename = argv + +print(f"We're going to erase {filename}.") +print("If you want to cancel, HIT CTRL-C (^C) NOW!!!") +print("If you want to proceed, hit Enter") + +input("?") + +print(f"Opening the file...{filename}") +target = open(filename, 'a') +#https://docs.python.org/3/library/functions.html#open documentation on open() + +#print("Truncating the file. Goodbye!") +#target.truncate() + +print("Now I'm going to ask you a write a few lines: ") + +Q1 = input("Line 1: ") +Q2 = input("Line 2: ") +Q3 = input("Line 3: ") + +print(f"Now I'll write the 3 lines to {filename}") + +allQ = Q1 + "\n" + Q2 + "\n" + Q3 + "\n" +target.write(allQ) +#target.write("\n") +#target.write(Q2) +#target.write("\n") +#target.write(Q3) +#target.write("\n") + +print(f"Finished writing, closing {filename}.") +target.close() diff --git a/python/lp3thw/Exercise17/ex17.py b/python/lp3thw/Exercise17/ex17.py new file mode 100644 index 0000000..5907a79 --- /dev/null +++ b/python/lp3thw/Exercise17/ex17.py @@ -0,0 +1,22 @@ +from sys import argv +from os.path import exists + +script, fromFile, toFile = argv + +print(f"Copying from {fromFile} into {toFile}") + +inFile = open(fromFile) +inData = inFile.read() + +print(f"The input file is {len(inData)} bytes long.") + +print(f"Does the output file exist? {exists(toFile)}") +print("Ready? hit RETURN to continue - ") + +input(" ------ ") + +outFile = open(toFile, "w") #use mode to so we make sure its a clean copy. Erases the file on opening +outFile.write(inData) + +outFile.close() +inFile.close() \ No newline at end of file diff --git a/python/lp3thw/Exercise18/ex18.py b/python/lp3thw/Exercise18/ex18.py new file mode 100644 index 0000000..8c781a1 --- /dev/null +++ b/python/lp3thw/Exercise18/ex18.py @@ -0,0 +1,18 @@ +def printTwo(*args): + arg1, arg2 = args + print(f"arg1: {arg1}, arg2: {arg2}") + +def printTwoAgain(arg1, arg2): + print(f"arg1: {arg1}. arg2: {arg2}") + +def printOne(arg1): + print(f"arg1: {arg1}") + +def printNone(): + print("No arguments here") + +printTwo("Ganome", "Mary") +printTwoAgain("Ganome", "Mary") +printOne("Single Argument") +printNone() + diff --git a/python/lp3thw/Exercise19/ex19.py b/python/lp3thw/Exercise19/ex19.py new file mode 100644 index 0000000..4035c2d --- /dev/null +++ b/python/lp3thw/Exercise19/ex19.py @@ -0,0 +1,21 @@ +def cheeseAndCrackers(cheeseCount, boxesOfCrackers): + print(f"You have {cheeseCount} cheeses!") + print(f"You have {boxesOfCrackers} boxes of crackers") + print("Man thats enough for a party!") + print("Get a blanket!\n") + +print("We can just give the function numbers directly") +cheeseAndCrackers(20, 30) + +print("OR, we can use variables from our script:") + +amountOfCheeses = 10 +amountOfCrackers = 50 + +cheeseAndCrackers(amountOfCheeses, amountOfCrackers) + +print("We can even do the math inside:") +cheeseAndCrackers(6 * 5, 24 + 16) + +print("And we can combine the two, variables and math:") +cheeseAndCrackers(amountOfCheeses + 32,amountOfCrackers + 5 * 4) \ No newline at end of file diff --git a/python/lp3thw/Exercise20/ex20.py b/python/lp3thw/Exercise20/ex20.py new file mode 100644 index 0000000..4f8e1f9 --- /dev/null +++ b/python/lp3thw/Exercise20/ex20.py @@ -0,0 +1,33 @@ +from sys import argv + +script, inputFile = argv + +def printAll(f): + print(f.read()) + +def rewind(f): + f.seek(0) + +def printALine(lineCount, f): + #print(lineCount, f.readline()) #THIS METHOD INCLUDES THE LINE NUMBER!!! + print(f.readline()) + +currentFile = open(inputFile) + +print("First let's print the whole file: \n") +printAll(currentFile) + +print("Now let's rewind. Kind of like a tape.") + +rewind(currentFile) + +print("Let's print three lines:") + +currentLine = 1 +printALine(currentLine, currentFile) + +currentLine += 1 +printALine(currentLine, currentFile) + +currentLine = currentLine + 1 #THIS is identical to the line above! +printALine(currentLine, currentFile) \ No newline at end of file