# cs homework- 1-3, 5 and midterm notes

Total word count: 2425
Pages: 9

### Calculate the Price

- -
275 words
Looking for Expert Opinion?
Let us have a look at your work and suggest how to improve it!
 initialize? assign a value to Assume that print_error_description is a function that expects one int parameter and returns no value. Write a statement that invokes the function print_error_description, passing it the value 14. print_error_description(14) Write the code to call the function named send_signal. There are no parameters for this function. send_signal() Write a statement that reads a word from standard input into firstWord. input() Write a statement that reads an integer value from standard input into a variable called val. val = int(input()) Write a statement that reads a floating point value from standard input into temperature. temperature = float(input()) Given a variable word that has been assigned a string value, write a string expression that parenthesizes the value of word. So, if word contains "sadly", the value of the expression would be the string "(sadly)" "(" + word + ")" Write the definition of a function twice, that receives an int parameter and returns an int that is twice the value of the parameter. def twice(x): return (2*x) Write the definition of a function named sum_list that has one parameter, a list whose elements are of type int. The function returns the sum of the elements of the list as an int. def sum_list(x): return sum(x) Given the variable c, whose associated value is a str, write an expression that is True if and only if c is not equal to a string consisting of a single blank. c != " " Assume that a variable variable , numberOfSides has been initialized. Write a statement that assigns the value True to the variable isQuadrilateral if numberOfSides is exactly 4 and False otherwise. isQuadrilateral = numberOfSides==4 Given a variable s that is associated with the empty string, write some statements that use a while loop to associate s with a string consisting of exactly 777 asterisks (*) . s="" x= "*" while len(s)<777: s= x x += "*" Write a statement that defines plist as the list containing exactly these elements (in order): "spam", "eggs", "vikings" . plist= ["spam","eggs","vikings"] Given a variable s that is associated with non-empty empty string, write some statements that use a while loop to associate a variable vowel_count with the number of lower-case vowels ("a","e","i","o","u") in the string . i=0 vowel_count=0 while i 1): has_dups = True else: has_dups = False Sort the list, lst (use the list sort method). lst.sort() Given that plist has been defined to be a list, write an expression that evaluates to True if 3 is an element of plist. 3 in plist Given that plist has been defined to be a list of 30 elements, add 5 to its last element. plist[-1] += 5 Given the lists, lst1 and lst2, create a new sorted list consisting of all the elements of lst1 that also appears in lst2. For example, if lst1 is [4, 3, 2, 6, 2] and lst2 is [1, 2, 4], then the new list would be [2, 2, 4]. Note that duplicate elements in lst1 that appear in lst2 are also duplicated in the new list. Associate the new list with the variable new_list, and don’t forget to sort the new list. new_list= [] for element in lst1: if element in lst2: new_list.append(element) new_list.sort() Given the string, s, and the list, lst, associate the variable contains with True if every string in lst appears in s (and False otherwise). Thus, given the string Hello world and the list ["H", "wor", "o w"], contains would be associated with True. contains = True for i in range(0, len(lst)): if not lst[i] in s: contains = False Assume that a list of integers named salary_steps that contains exactly five elements has been defined. Write a statement that changes the value of the last element in the list to 160000. salary_steps[-1] = 160000 Given a variable named plist that refers to a list, write a statement that adds another element, 5 to the end of the list. plist.append(5) Given that play_list has been defined to be a list, write a statement that makes the first 3 elements of play_list be "spam", "eggs" and "vikings" (in that order). play_list[0:3] = ["spam","eggs","vikings"] Given that alist has been defined to be a list with at least 4 elements, write a statement that removes its 4th element. del alist Given that a refers to a list, write the necessary code to reverse the elements of the list. a.reverse() Given that k refers to an int and that play_list has been defined to be a list, write a expression that evaluates to True if the value associated with k is an element of play_list. k in play_list Given a list named alist, write an expression that removes the last element of alist. del(list[-1]) Given that plist1 and plist2 both refer to lists, write a statement that defines plist3 as a new list that is the concatenation of plist1 and plist2. Do not modify plist1 or plist2. plist2= plist1 + plist2 Given that t has been defined and refers to a tuple write a statement that associates play_list with a list containing the same elements as t. play_list=list(t) Assume that plist refers to a list containing exactly five elements. Assume, in addition, that j refers to an int with a value that is between 0 and 3. Write a statement that associates a new value with the element of the list indexed by j. This new value should be equal to twice the value of the next element of the list (i.e. the element after the element indexed by j. plist[j]= 2*plist[j+1] Write the definition of a function, is_reverse, whose two parameters are arrays of integers of equal size. The function returns true if and only if one array is the reverse of the other. ("Reverse" here means same elements but in reverse order.) def is_reverse(x,y): if y==x[::-1]: return True else: return False Write a statement that associates t with the empty tuple. t=() Given a variable t that is associated with a tuple whose elements are numbers, write some statements that use a while loop to count the number of times the first element of the tuple appears in the rest of the tuple, and associate that number with the variable repeats. Thus if the tuple contains (1,6,5,7,1,3,4,1), then repeats would be assigned the value 2 because after the first "1" there are two more "1"s. repeats=0 i=1 while i

### More flashcards like this

#### NCLEX 10000 Integumentary Disorders

When assessing a client with partial-thickness burns over 60% of the body, which finding should the nurse report immediately? a) ...

#### NCLEX 300-NEURO

A client with amyotrophic lateral sclerosis (ALS) tells the nurse, "Sometimes I feel so frustrated. I can’t do anything without ...

#### NASM Flashcards

Which of the following is the process of getting oxygen from the environment to the tissues of the body? Diffusion ...

## Unfinished tasks keep piling up?

Let us complete them for you. Quickly and professionally.

Check Price 