Skip to content
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
25 changes: 24 additions & 1 deletion chapter2_exercises.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
# Exercises for chapter 2:

# Name:
# Name:Shishira Adiga

#Exercise 2.1--appending 0 indicates octal system hence outputs octal value of the integer typed.

#Exercise 2.2
print 5
#print x = 5 --this as per textbook produceses syntax error
x = 5
print x+1
#this code outputs 5 and 6

# Exercise 2.3
#1.width/2 -- value = 8;type = integer.
#2.widht/2.0 -- value = 8.5;type = float.
#3.height/3 -- value =4.0 ; type = float.
#4.1+2*5 -- value = 11; type=integer.
#5.delimiter*5 -- value = .....;type = string;

#Exercise 2.4
#1--4/3.0*pi*5**3 = 523.333
#2--$1574.2
#3--7 hours 30 mins 6 seconds


72 changes: 71 additions & 1 deletion chapter3_exercises.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,73 @@
# Exercises for chapter 3:

# Name:
# Name:Shishira Adiga

#3.1
'''def print_lyrics():
print "I'm a lumberjack, and I'm okay."
print "I sleep all night and I work all day."

def repeat_lyrics():
print_lyrics()
print_lyrics()

repeat_lyrics()'''

#3.1
#NameError: 'repeat_lyrics' is not defined

#3.2
#I'm a lumberjack, and I'm okay.
#I sleep all night and I work all day.
#I'm a lumberjack, and I'm okay.
#I sleep all night and I work all day.
#question--how come you get the right answer?since you're calling function print_lyrics before defination.

#3.3
def right_justify(s):
b=len(s)
print(' '*(70-b)+s)

right_justify('time')

#3.4
#1
def do_twice(f):
f()
f()

def print_spam():
print 'spam'

do_twice(print_spam)

#2
def do_twice(f,g):
f(g)
f(g)

def print_twice(s):
print s*2

do_twice(print_twice,'start')

#3
def print_twice(s):
print s*2

print_twice('start')

#4
def do_four(f,g):
do_twice(f,g)
do_twice(f,g)

def do_twice(f,g):
f(g)
f(g)

def print_twice(s):
print s*2


do_four(print_twice,'start')