Skip to content

Commit 457c164

Browse files
authored
Add files via upload
1 parent e3e6069 commit 457c164

23 files changed

+249
-0
lines changed

carroll.txt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Beware the Jabberwock, my son,
2+
the jaws that bite, the claws that catch,
3+
Beware the JubJub bird and shun
4+
the frumious bandersnatch.

forLines.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Tue Oct 20 18:28:59 2020
4+
5+
@author: xyz
6+
"""
7+
8+
info = open("hours.txt")
9+
10+
for eachLine in info:
11+
print(eachLine)

hours.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
123 Susan 12.5 8.1 7.6 3.2
2+
456 Brad 4.0 11.6 6.5 2.7 12
3+
789 Jenn 8.0 8.0 8.0 8.0 7.5

joinString.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Tue Oct 20 18:41:04 2020
4+
5+
@author: xyz
6+
"""
7+
8+
9+
names = ['Alice', 'Bob', 'Candi', 'Dave', 'Eve']
10+
11+
namesJoin = "_".join(names)
12+
print(namesJoin)
13+
14+
namesJoin2 = " <3 ".join(names)
15+
print(namesJoin2)

lineOne.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Tue Oct 20 18:26:44 2020
4+
5+
@author: xyz
6+
"""
7+
8+
info = open("hours.txt")
9+
lineOne = info.readline()
10+
print(lineOne)
11+
12+
lineTwo = info.readline()
13+
print(lineTwo)

listOfLines.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Tue Oct 20 18:27:37 2020
4+
5+
@author: xyz
6+
"""
7+
8+
info = open("hours.txt")
9+
listOfLines = info.readlines()
10+
print(listOfLines)
11+
12+
print(listOfLines[0])
13+
print(listOfLines[1])
14+
print(listOfLines[2])
15+

longest.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Tue Oct 20 19:08:05 2020
4+
5+
@author: xyz
6+
"""
7+
8+
9+
def main():
10+
input = open("carroll.txt")
11+
longest = ""
12+
for line in input:
13+
if len(line) > len(longest):
14+
longest = line
15+
16+
print("Longest line =", len(longest))
17+
print(longest)
18+
main()

loopSplit.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Tue Oct 20 18:39:06 2020
4+
5+
@author: xyz
6+
"""
7+
8+
9+
hello = "hello how are you?"
10+
splitHello = hello.split()
11+
print(splitHello)
12+
13+
joinList = " <3 ".join(splitHello)
14+
print(joinList)

names.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
John Snow
2+
Albert Einstein
3+
Andrew Ng
4+
Ian Goodfellow
5+
Geoffrey Hinton

newfile.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Something else!
2+
This will be added!
3+
This other sentence will be added in new line!

out_username.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
jsnow
2+
aeinstei
3+
ang
4+
igoodfel
5+
ghinton

output-newfile.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SOMETHING ELSE!
2+
THIS WILL BE ADDED!
3+
THIS OTHER SENTENCE WILL BE ADDED IN NEW LINE!

scores.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2.5 8.1 7.6 3.2 3.2
2+
3.0 11.6 6.5 2.7 12.4
3+
8.0 8.0 8.0 8.0 7.5

split.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Tue Oct 20 18:36:28 2020
4+
5+
@author: xyz
6+
"""
7+
8+
9+
line = "hello world this is my song\n"
10+
lineSplit = line.split()
11+
print(lineSplit)
12+
13+
whiteCat = "\t\nI love\t\t\nwhitespace\n "
14+
whiteCatSplit = whiteCat.split()
15+
print(whiteCatSplit)
16+
17+
18+
commas = "once,twice,thrice"
19+
commasSplit = commas.split(",")
20+
print(commasSplit)
21+
22+
double = "hello how ill are all of your llamas?"
23+
doubleLLSplit = double.split("ll")
24+
print(doubleLLSplit)

splitVariable.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Tue Oct 20 18:43:45 2020
4+
5+
@author: xyz
6+
"""
7+
8+
9+
s = "Jessica 31 647.28"
10+
name, age, money = s.split()
11+
print(name)
12+
print(age)
13+
print(money)

test-file.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Wed Oct 21 15:50:33 2020
4+
5+
@author: ucobiz
6+
"""
7+
8+
test_content = open("test-file.txt")
9+
print(test_content)

test-file.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Hello
2+
I'm learning Python!

userfile.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Tue Oct 20 19:00:01 2020
4+
5+
@author: xyz
6+
"""
7+
8+
9+
def main():
10+
print ("This program creates a file of usernames from a")
11+
print ("file of names.")
12+
13+
# get the file names
14+
infileName = input("What file are the names in? ")
15+
outfileName = input("What file should the usernames go in? ")
16+
17+
# open the files
18+
infile = open(infileName, 'r')
19+
outfile = open(outfileName, 'w')
20+
21+
# process each line of the input file
22+
for line in infile:
23+
# get the first and last names from line
24+
first, last = line.split()
25+
# create a username
26+
uname = (first[0]+last[:7]).lower()
27+
# write it to the output file
28+
print(uname, file=outfile)
29+
30+
# close both files
31+
infile.close()
32+
outfile.close()
33+
34+
print("Usernames have been written to", outfileName)
35+
36+
main()

username.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
jsnow
2+
aeinstei
3+
ang
4+
igoodfel
5+
ghinton

wholething.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Tue Oct 20 18:25:11 2020
4+
5+
@author: xyz
6+
"""
7+
8+
info = open("hours.txt")
9+
wholeThing = info.readline()
10+
print(wholeThing)

workerHours.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Tue Oct 20 18:48:39 2020
4+
5+
@author: xyz
6+
"""
7+
8+
9+
def main():
10+
input = open("workerHours.txt")
11+
for line in input:
12+
id, name, mon, tue, wed, thu, fri = line.split()
13+
# cumulative sum of this employee's hours
14+
hours = float(mon) + float(tue) + float(wed) + float(thu) + float(fri)
15+
print(name, "ID", id, "worked", hours, "hours: ", hours/5, "/ day")
16+
17+
main()
18+

workerHours.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
123 Suzy 9.5 8.1 7.6 3.1 3.2
2+
456 Brad 7.0 9.6 6.5 4.9 8.8
3+
789 Jenn 8.0 8.0 8.0 8.0 7.5

writeFile.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Wed Oct 21 16:50:47 2020
4+
5+
@author: ucobiz
6+
"""
7+
8+
inputObj = open("newfile.txt")
9+
outputObj = open("output-newfile.txt", "w")
10+
11+
# convert the sentence into UPPERCASE
12+
for sentence in inputObj:
13+
newSentenceUpper = sentence.upper()
14+
outputObj.writelines(newSentenceUpper)
15+
16+
inputObj.close()
17+
outputObj.close()

0 commit comments

Comments
 (0)