Reply
Old 03-13-2013, 10:04 PM   #1 (permalink)
 
Status: Member
Posts: 45



Default i need help with programminglab for python..

1.Associate True with the variable is_ascending if the list numbers is in ascending order (that is, if each element of the list is greater than or equal to the previous element in the list). Otherwise, associate False with is_ascending

2.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 .

3. We informally define the term corresponding element as follows:
The first element and the last element of a list are corresponding elements.
Similarly, the second element and the element just before the last element are corresponding elements.
The third element and the element just before the element just before the last element are corresponding elements -- and so on.

Given that the variable a is associated with a list, write an expression for the corresponding element of a[i] . * *

4. Assume that print_list is a function that expects one parameter, a list. The function prints the contents of the list; it does not return a value.

Assume that inventory is a list, each of whose elements is an int .



Write a statement that prints the contents of the list inventory by calling the function print_list

5. Associate the sum of the non-negative values in the list numbers with the variable sum .

6.
Given:
a variable named incompletes that refers to a list of student ids, and
a variable student_id

Write some code that counts the number of times the value associated with student_id appears in the list associated with incompletes and assigns this value to number_of_incompletes . You may use, if you wish, an additional variable, k .

You may use only k , incompletes , student_id , and number_of_incompletes .

7. A list named parking_tickets has been defined to be the number of parking tickets given out by the city police each day since the beginning of the current year. (Thus, the first element of the list contains the number of tickets given on January 1; the last element contains the number of tickets given today.)

Write some code that associates most_tickets with the largest value found in parking_tickets . You may, if you wish, use one additional variable, k .

8. 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 .

9.
You are given a variable zipcode_list that refers to a list.

Write some code that assigns True to a variable duplicates if there are two adjacent elements in the list that have the same value, but that otherwise assigns False to duplicates otherwise. In order to accomplish this, you may, if you wish, use one other variable, k .

10.
You are given a variable named zipcode_list that has been defined and refers to a list of postal codes.

Write some code that assigns True to duplicates if any two elements in the list have the same value, but that otherwise assigns False to duplicates . You may, if you wish, use two other variables, j and k .

Use only j , k , zipcode_list , and duplicates

11. 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.

12. 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.)

13. Given the lists list1 and list2 , not necessarily of the same length, create a new list consisting of alternating elements of list1 and list2 (that is, the first element of list1 followed by the first element of list2 , followed by the second element of list1 , followed by the second element of list2 , and so on. Once the end of either list is reached, the remaining elements of the longer list is added to the end of the new string. For example, if list1 contained [1, 2, 3] and list2 contained [4, 5, 6, 7, 8] , then the new list should contain [1, 4, 2, 5, 3, 6, 7, 8] . Associate the new list with the variable list3

Thanks for hopefully some good useful help!
Chandler is offline   Reply With Quote

Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is Python for dummies 2006 too oudated to get familliar with python?if so any free books out there? The_Guardian_Angel Coding 0 02-13-2013 09:05 PM
i started learning programming in python but should i change and learn something else or continue with python? Unknown_User Programming 1 07-26-2012 11:07 AM
Where can I download the coding software Python that the tutor on Khanacademy uses for Python programming? Unknown_User Coding 0 05-21-2012 10:37 AM
I Can Only Input Python Code By Line - Simple Python Program Issues? Unknown_User Coding 0 02-07-2012 12:07 AM
Python, delete a file on opening in python command prompt or running in GUI but not if rerun from GUI? Nado_Rankx_Jamaican_Daps Programming 0 01-13-2012 03:37 AM