Skip to content

Commit b628215

Browse files
Update to python 3.4
1 parent fd9445e commit b628215

File tree

11 files changed

+57
-57
lines changed

11 files changed

+57
-57
lines changed

exercise-10.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
\t* Fishies
88
\t* Catnip\n\t* Grass
99
"""
10-
print tabby_cat
11-
print persian_cat
12-
print backslash_cat
13-
print fat_cat
10+
print(tabby_cat)
11+
print(persian_cat)
12+
print(backslash_cat)
13+
print(fat_cat)
1414

1515
while True:
1616
for i in ["/","-","|","\\","|"]:
17-
print "%s\r" % i,
17+
print("%s\r" % i, end=" ")

exercise-11.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
print "How old are you?"
2-
age = raw_input()
3-
print "So, you're %r old" % age
1+
print("How old are you?")
2+
age = input()
3+
print("So, you're %r old" % age)

exercise-12.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
age = raw_input("How old are you? ")
2-
height = raw_input("How tall are you? ")
3-
print "So, you're %r old and %r tall" % (age, height)
1+
age = input("How old are you? ")
2+
height = input("How tall are you? ")
3+
print("So, you're %r old and %r tall" % (age, height))

exercise-13.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
script, first, second, third = argv
44

5-
print "script", script
6-
print "first", first
7-
print "second", second
8-
print "third", third
5+
print("script", script)
6+
print("first", first)
7+
print("second", second)
8+
print("third", third)
99

1010
# python exercise-13.py um dois tres

exercise-14.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@
33
script, user_name = argv
44
prompt = '> '
55

6-
print "Hi %s, I'm the %s script." % (user_name, script)
7-
print "I'd like to ask you a few questions."
8-
print "Do you like me %s" % user_name
9-
likes = raw_input(prompt)
6+
print("Hi %s, I'm the %s script." % (user_name, script))
7+
print("I'd like to ask you a few questions.")
8+
print("Do you like me %s" % user_name)
9+
likes = input(prompt)
1010

11-
print "Where do you like %s?" % user_name
12-
lives = raw_input(prompt)
11+
print("Where do you like %s?" % user_name)
12+
lives = input(prompt)
1313

14-
print "What kind of computer do you have?"
15-
computer = raw_input(prompt)
14+
print("What kind of computer do you have?")
15+
computer = input(prompt)
1616

17-
print """
17+
print("""
1818
Alright, so you said %r about liking me.
1919
You live in %r. Not sure where that is.
2020
And you have a %r computer. Nice.
21-
""" % (likes, lives, computer)
21+
""" % (likes, lives, computer))
2222

2323
# python exercise-14.py zampi

exercise-15/exercise-15.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
script, filename = argv
44
txt = open(filename)
55

6-
print "Here's your file %r:" % filename
7-
print txt.read()
6+
print("Here's your file %r:" % filename)
7+
print(txt.read())
88

9-
print "Type the filename again:"
10-
file_again = raw_input("> ")
9+
print("Type the filename again:")
10+
file_again = input("> ")
1111

1212
txt_again = open(file_again)
1313

14-
print txt_again.read()
14+
print(txt_again.read())
1515

1616
# python exercise-15.py exercise-15-sample.txt

exercise-16/exercise-16.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@
22

33
script, filename = argv
44

5-
print "We're going to erase %r." % filename
6-
print "If you don't want that, hit CTRL-C (^C)."
7-
print "If you do want that, hit RETURN."
5+
print("We're going to erase %r." % filename)
6+
print("If you don't want that, hit CTRL-C (^C).")
7+
print("If you do want that, hit RETURN.")
88

9-
raw_input("?")
9+
input("?")
1010

11-
print "Opening the file ..."
11+
print("Opening the file ...")
1212
target = open(filename, "w")
1313

14-
print "Truncating the file. Goodbye!"
14+
print("Truncating the file. Goodbye!")
1515
target.truncate()
1616

17-
print "Now I'm going to ask you for three lines."
17+
print("Now I'm going to ask you for three lines.")
1818

19-
line1 = raw_input("line 1: ")
20-
line2 = raw_input("line 2: ")
21-
line3 = raw_input("line 3: ")
19+
line1 = input("line 1: ")
20+
line2 = input("line 2: ")
21+
line3 = input("line 3: ")
2222

23-
print "I'm going to write these to the file."
23+
print("I'm going to write these to the file.")
2424

2525
target.write(line1)
2626
target.write("\n")
@@ -29,7 +29,7 @@
2929
target.write(line3)
3030
target.write("\n")
3131

32-
print "And finally, we close it."
32+
print("And finally, we close it.")
3333
target.close()
3434

3535
#python exercise-16.py test.txt

exercise-17/exercise-17.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@
33

44
script, from_file, to_file = argv
55

6-
print "Copyng from %s to %s" % (from_file, to_file)
6+
print("Copyng from %s to %s" % (from_file, to_file))
77

88
# we could do these two on one line, how?
99
in_file = open(from_file)
1010
indata = in_file.read()
1111

12-
print "The input file is %d bytes long" % len(indata)
12+
print("The input file is %d bytes long" % len(indata))
1313

14-
print "Does the output file exist? %r" % exists(to_file)
15-
print "Ready, press ENTER to continue, CTRL-C to abort."
16-
raw_input()
14+
print("Does the output file exist? %r" % exists(to_file))
15+
print("Ready, press ENTER to continue, CTRL-C to abort.")
16+
input()
1717

1818
out_file = open(to_file, "w")
1919
out_file.write(indata)
2020

21-
print "Alright, all done."
21+
print("Alright, all done.")
2222

2323
out_file.close()
2424
in_file.close()

exercise-18/exercise-18.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
def print_two(*args):
22
arg1, arg2 = args
3-
print "arg1: %r, arg2: %r" % (arg1, arg2)
3+
print("arg1: %r, arg2: %r" % (arg1, arg2))
44

55

66
def print_two_again(arg1, arg2):
7-
print "arg1: %r, arg2: %r" % (arg1, arg2)
7+
print("arg1: %r, arg2: %r" % (arg1, arg2))
88

99

1010
def print_one(arg1):
11-
print "arg1: %r" % arg1
11+
print("arg1: %r" % arg1)
1212

1313

1414
def print_none():
15-
print "I got nothin'."
15+
print("I got nothin'.")
1616

1717

1818
print_two("Zed", "Shaw")

exercise-8.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
formatter = "%r %r %r %r"
22

3-
print formatter % (1, 2, 3, 4)
4-
print formatter % (
3+
print(formatter % (1, 2, 3, 4))
4+
print(formatter % (
55
"I has this thing",
66
"That yout could type up right",
77
"But it didn't sing.",
88
"So I said goodnight"
9-
)
9+
))

exercise-9.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
days = "Mon Tue Wed Thu Fri Sat Sun"
22
months = "\nJan\nFeb\nMar\nApr\nMay\nJun"
3-
print "Days:", days
4-
print "Months:", months
3+
print("Days:", days)
4+
print("Months:", months)

0 commit comments

Comments
 (0)