#5.15
def vowels(s):
for i in range( len(s) ):
if s[i] in "aeiouAEIOU":
print(i)
#5.16
def indexes(word, char):
' returns list of all indices where char appears in word'
inds = []
for i in range( len(word) ):
if word[i] = char:
inds.append( i )
return ind
# finalPractice.py - practice problems for final
'
Disclaimer: this is not intended to be a comprehensive
review for the exam.
I recommend that you solve these without IDLE then go back
to IDLE and make sure you understand the answers
'
# programming #
#
"
Paste the solutions to problems 4.17, 4.18, 4.19, and 4.20 here:
#4.17
> message = "The secret of this message is that it is secret."
> length = len( message )
> count = message.count("secret")
> censored = message.replace("secret","xxxxxx")
> censored
# hw5.py - solutions due to L. Perkovic (perhaps w/ edits by E. Sedgwick)
#homework5.py
#5.25, 5.28, 5.36, 5.38, 5.42, 5.48
# 5.25
def leap(y):
return (y%4=0 and y%100!=0) or y%400=0
#5.28
def geometric( seq ):
# compare each ratio to first ration
# note,
# hw7.py - solutions due to L. Perkovic (perhaps w/ edits by E. Sedgwick)
# 5.41,10.16, 10.19, 10.29, 10.32(a)
def poly( coeffs, value):
p = 0
for i in range( len(coeffs):
p+=coeffs[i]*value*i
return p
def combinations(n,k):
if k<=0:
return 1
elif n<k:
re
# hw6.py - solutions due to L. Perkovic (perhaps w/ edits by E. Sedgwick)
# 5.49
def heron( n, error):
curr = 1
while True:
curr, prev = 1/2*(curr + n/curr), curr
if abs(curr-prev)<error:
return curr
#6.22
def mirror(word):
# dict of mirrorable characters
# hw8.py - solutions due to L. Perkovic (perhaps w/ edits by E. Sedgwick)
# 5.42, 10.23, 10.30
# 5.42 - could also be done iteratively with nested loop
def primeFac(n):
# look, for a divisor,
# if one is found, it will be prime, recursively
# find more
fo
# hw2.py - most solutions by L. Perkovic
#solutions for hw2
#3.23 part (f)
def forLoops():
for i in range(5,22,4):
print( i )
# 3.34
def pay(hourlyWage, numHours):
if numHours <= 40:
return numHours*hourlyWage
else:
return numHours*hourlyWage+(numHours-40
# hw3.py - solutions due to L. Perkovic (perhaps w/ edits by E. Sedgwick)
"
Paste the solutions to problems 4.17, 4.18, 4.19, and 4.20 here:
#4.17
> message = "The secret of this message is that it is secret."
> length = len( message )
> count = message.c
# hw4.py - solutions due to L. Perkovic (perhaps w/ edits by E. Sedgwick)
#5.15
def vowels(s):
for i in range( len(s) ):
if s[i] in "aeiouAEIOU":
print(i)
#5.16
def indexes(word, char):
' returns list of all indices where char appears in word'
inds = []
f
# midtermPractice.py - practice problems for midter
'
Disclaimer: this is not intended to be a comprehensive
review for the exam. It is intended to give you practice
solving problems similar to those that will be covered.
I recommend that you solve these
CSC 241
Lab #2
Due: 10 minutes after lab ends
1. Write Python statements in the shell that correspond to the following:
a. Assign to variable flowers a list containing strings rose, bougainvillea, yucca, marigold,
daylilly, and lilly of the valley.
b. Wri
# CSC401-Database Design
# Assignment Three
#Problem One
def evenOdd():
integers=[50,32,77,-43,-69,-22,-18,10,38,97,21,94,3,-99,-37,-17,13,82,11,53]
even=[x for x in integers if x%2=0]
odd=[x for x in integers if x%2!=0]
print(even,'has ',len(even),'even
# -*- coding: utf-8 -*"
Created on Tue Apr 21 21:17:22 2015
@author: jasminedumas
"
def ageAfter(x):
return x - 21
ask = eval(input("Enter your age old head: ")
value = ageAfter(ask)
print(value)
def ageYears(y):
return y * 12
ask = eval(input("Enter your age in years: ")
value = ageYears(ask)
if ask < 6:
print("How did you learn how to use a computer, baby?")
else:
print("Your months on earth:", value)
# return two lists from one string of names
def breakup2(str1):
str1 = str1.lower()
list1 = str1.split()
wordList1 = []
#intilizing a NULL list
wordList2 = []
for word in list1:
if word[0] >= 'a' and word[0] <= 'm':
wordList1.append(word) # adds word to t
def avg(value1, value2):
average = (value1 + value2) / 2
# print("The result is: ", average) # It also work not commented too!
Let's see if removing this works also: it does!
return average # this works
val1 = eval(input("Enter first value: ")
val2 = eval
'
While - indefinite loop
write a function that prompts the user to enter cities and appends to a list
and stops when a null string is entered/just hiting enter
'
def cities():
lst = []
city = input("Enter a city (NULL to stop): ")
while city != ':
lst.ap
' write a function that excepts one paramter, a string then
returns two values, the first value of the number of words
that start with 'a' through 'm' and then the second value
of the number of words 'n' through 'z' '
def breakup(str1):
count1 = 0 # defin
' write a function that accepts a parameter as a file name and
returns the number of occurances of certain words'
def words(filename):
countlab = 0 # define start of count for 'laboratory'
countFrank = 0 # define start of count for 'Frankenstein'
countmon
import random
def shuffleDeck():
suits = cfw_'\u2660','\u2661','\u2662','\u2663'
ranks = cfw_'2','3','4','5','6','7','8','9','10','J','Q','K','A'
deck = []
for suit in suits:
for rank in ranks:
deck.append(rank + ' ' + suit)
random.shuffle(deck)
# Now shu
'
Dictionary practice 5/20/15
'
str1 = "this is a test to see if this works"
#str1 = str1.split()
letters = cfw_
# empty dictionary letters = cfw_"t":'1', "h": "2".
strlen = len(str1)
# length of example sentence
for i in range(strlen):
if str1[i] in lett
CSC 241
Lab #3
Due: 10 Minutes After Lab Ends
1. Implement the function returnThree that takes a string as a parameter and returns the first three
characters of the string. If the string has length less than 3, then an empty string should be
returned. The