From 96ba3888bdad337e7a91d79c895ca3892fa883db Mon Sep 17 00:00:00 2001 From: brysonS Date: Mon, 8 Mar 2021 13:22:10 -0500 Subject: [PATCH 1/2] Python modules 0-7 --- src/00_hello.py | 9 ++++++++- src/01_bignum.py | 5 ++++- src/02_datatypes.py | 6 +++++- src/03_modules.py | 10 +++++++++- src/07_slices.py | 2 +- 5 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/00_hello.py b/src/00_hello.py index 268998dfc7..54d51b12b2 100644 --- a/src/00_hello.py +++ b/src/00_hello.py @@ -1 +1,8 @@ -# Print "Hello, world!" to your terminal \ No newline at end of file +# Print "Hello, world!" to your terminal + +print("Herro World!") + +greeting = "hey there," +name = "bryson" + +print(greeting + name) \ No newline at end of file diff --git a/src/01_bignum.py b/src/01_bignum.py index c020928d63..616d9bee10 100644 --- a/src/01_bignum.py +++ b/src/01_bignum.py @@ -1,4 +1,7 @@ # Print out 2 to the 65536 power # (try doing the same thing in the JS console and see what it outputs) -# YOUR CODE HERE \ No newline at end of file +# YOUR CODE HERE +bignum = 65536 +power2 = 2 +print(bignum * power2) \ No newline at end of file diff --git a/src/02_datatypes.py b/src/02_datatypes.py index 245193da34..b3d3c8d4be 100644 --- a/src/02_datatypes.py +++ b/src/02_datatypes.py @@ -15,7 +15,11 @@ # YOUR CODE HERE +print(x + int(y)) + # Write a print statement that combines x + y into the string value 57 -# YOUR CODE HERE \ No newline at end of file +# YOUR CODE HERE + +print(str(x) + y) \ No newline at end of file diff --git a/src/03_modules.py b/src/03_modules.py index 97eba053c7..579d4da6b9 100644 --- a/src/03_modules.py +++ b/src/03_modules.py @@ -4,28 +4,36 @@ methods, and the os module, which gives you access to lower- level operating system functionality. """ +## PRACTICE WITH PRINT STATEMENTS AND FORMAT STRINGS import sys # See docs for the sys module: https://docs.python.org/3.7/library/sys.html # Print out the command line arguments in sys.argv, one per line: # YOUR CODE HERE +print(f"Here is the command line args: {sys.argv}") # Print out the OS platform you're using: # YOUR CODE HERE +print(f"The platform OS is: {sys.platform}") # Print out the version of Python you're using: # YOUR CODE HERE - +print(f"The version of Python: {sys.version}") import os # See the docs for the OS module: https://docs.python.org/3.7/library/os.html # Print the current process ID # YOUR CODE HERE +print(f"This is currrent process ID: {os.getpid()}") +#print(f"My curretn process ID: {os.getpid}") # Print the current working directory (cwd): # YOUR CODE HERE +# #print(f"My current working dir is: {os.cwd}") +print(f"This is cwd: {os.getcwd()}") # Print out your machine's login name # YOUR CODE HERE +print(f"This is your machines Username: {os.uname().machine}") \ No newline at end of file diff --git a/src/07_slices.py b/src/07_slices.py index 5e0b3bd8ee..02be1b0122 100644 --- a/src/07_slices.py +++ b/src/07_slices.py @@ -12,7 +12,7 @@ a = [2, 4, 1, 7, 9, 6] # Output the second element: 4: -print() +print(a[1]) # Output the second-to-last element: 9 print() From 97ac02ceeb4efdd9e2664e3b72558b1e6cac3028 Mon Sep 17 00:00:00 2001 From: brysonS Date: Mon, 8 Mar 2021 17:56:43 -0500 Subject: [PATCH 2/2] sclice practice --- src/04_printing.py | 1 + src/07_slices.py | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/04_printing.py b/src/04_printing.py index 06aaa7ff16..a301affb7d 100644 --- a/src/04_printing.py +++ b/src/04_printing.py @@ -11,6 +11,7 @@ # Using the printf operator (%), print the following feeding in the values of x, # y, and z: # x is 10, y is 2.25, z is "I like turtles!" +printf("x is %") # Use the 'format' string method to print the same thing diff --git a/src/07_slices.py b/src/07_slices.py index 02be1b0122..d0169926e5 100644 --- a/src/07_slices.py +++ b/src/07_slices.py @@ -8,30 +8,35 @@ Use Python's slice syntax to achieve the following: """ - +# 0 1 2 3 4 5 a = [2, 4, 1, 7, 9, 6] # Output the second element: 4: print(a[1]) # Output the second-to-last element: 9 -print() +print(a[-2]) # Output the last three elements in the array: [7, 9, 6] -print() +print(a[3:6]) # Output the two middle elements in the array: [1, 7] -print() +#print(a[:2], a[:3]) +mid = slice(2, 4) +print(a[mid]) # Output every element except the first one: [4, 1, 7, 9, 6] -print() +firstNum = slice(1, 6) +print(a[firstNum]) # Output every element except the last one: [2, 4, 1, 7, 9] -print() +lastNum = slice(1, 5) +print(a[lastNum]) # For string s... - +# 0,1, s = "Hello, world!" # Output just the 8th-12th characters: "world" -print() \ No newline at end of file +getWorld = slice(7, 12) +print(s[getWorld]) \ No newline at end of file