Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

intro to .py #1156

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/00_hello.py
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
# Print "Hello, world!" to your terminal
# Print "Hello, world!" to your terminal

print("Herro World!")

greeting = "hey there,"
name = "bryson"

print(greeting + name)
5 changes: 4 additions & 1 deletion src/01_bignum.py
Original file line number Diff line number Diff line change
@@ -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
# YOUR CODE HERE
bignum = 65536
power2 = 2
print(bignum * power2)
6 changes: 5 additions & 1 deletion src/02_datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
# YOUR CODE HERE

print(str(x) + y)
10 changes: 9 additions & 1 deletion src/03_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
1 change: 1 addition & 0 deletions src/04_printing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
23 changes: 14 additions & 9 deletions src/07_slices.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
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()
getWorld = slice(7, 12)
print(s[getWorld])