All Matches
Solution Library
Expert Answer
Textbooks
Search Textbook questions, tutors and Books
Oops, something went wrong!
Change your search query and then try again
Toggle navigation
FREE Trial
S
Books
FREE
Tutors
Study Help
Expert Questions
Accounting
General Management
Mathematics
Finance
Organizational Behaviour
Law
Physics
Operating System
Management Leadership
Sociology
Programming
Marketing
Database
Computer Network
Economics
Textbooks Solutions
Accounting
Managerial Accounting
Management Leadership
Cost Accounting
Statistics
Business Law
Corporate Finance
Finance
Economics
Auditing
Hire a Tutor
AI Tutor
New
Search
Search
Sign In
Register
study help
computer science
starting out with python
Questions and Answers of
Starting Out With Python
If you have downloaded the source code you will find the following files in the Chapter 07 folder:• GirlNames.txt This file contains a list of the 200 most popular names given to girls born in the
If you have downloaded the source code you will find a file named USPopulation.txt in the Chapter 07 folder. The file contains the midyear population of the United States, in thousands, during the
If you have downloaded the source code you will find a file named WorldSeriesWinners. txt in the Chapter 07 folder. This file contains a chronological list of the World Series winning teams from 1903
Write a program that asks the user for the name of a file. The program should read all of the file’s data into a list and display the number of lines of data that the file contains, and then ask
What will the following code display?number 1 = 10number 2 = 5number 1 = number 1 + number 2print(number1)print(number2)
This removes an item at a specific index in a list.a. The remove methodb. The delete methodc. The del statementd. The kill method
What will the following code display?numbers = [1, 2, 3, 4, 5]my_list = numbers[1:]print(my_list)
This string method returns true if a string contains only numeric digits and is at least one character in length.a. The digit methodb. The isdigit methodc. The numeric methodd. The isnumber method
Assume mystring references a string. Write a statement that uses a slicing expression and displays the last 3 characters in the string.
Write a program that lets the user enter a string and displays the character that appears most frequently in the string.
What will the following code display?mystring = 'abcdefg'print(mystring[:])
This string method returns a copy of the string with all leading and trailing whitespace characters removed.a. Cleanb. Stripc. Remove_whitespaced. Rstrip
Look at the following statement:levels = 'Beginner, Average, Advanced, Expert'Write a statement that splits this string, creating the following list:['Beginner', 'Average', 'Advanced', 'Expert']
You use _________ to delete an element from a dictionary.a. The remove methodb. The erase methodc. The delete methodd. The del statement
Write a statement that creates an empty dictionary.
Write a program that uses a dictionary to assign “codes” to each letter of the alphabet. For example:Using this example, the letter A would be assigned the symbol %, the letter a would be
The _________ function returns the number of elements in a dictionary:a. Size()b. Len()c. Elements()d. Count()
A compound Boolean expression created with the __________ operator is true only if both of its subexpressions are true.a. Andb. Orc. Notd. Both
Write an if statement that uses the turtle graphics library to determine whether the turtle’s pen size is greater than 1 or the pen color is red. If so, set the pen size to 1 and the pen color to
What will the following code display? total = 0 for count in range (1, 6): total = total + count print (total)
True or FalseA flowchart shows the hierarchical relationships between functions in a program.
What scope do parameter variables have?
Look at the following function definition:def my_function(x, y):return x[y]a. Write a statement that calls this function and uses keyword arguments to pass ‘testing’ into x and 2 into y.b. What
A county collects property taxes on the assessment value of property, which is 60 percent of the property’s actual value. For example, if an acre of land is valued at $10,000, its assessment value
How can functions make it easier for programs to be developed by teams of programmers?
A __________ is a diagram that gives a visual representation of the relationships between functions in a program.a. Flowchartb. Function relationship chartc. Symbol chartd. Hierarchy chart
True or FalseA hierarchy chart does not show the steps that are taken inside a function.
Why do global variables make a program difficult to debug?
Write a statement that generates a random number in the range of 1 through 100 and assigns it to a variable named rand.
A nutritionist who works for a fitness club helps members by evaluating their diets. As part of her evaluation, she asks members for the number of fat grams and carbohydrate grams that they consumed
A function definition has what two parts?
A __________ is a variable that is created inside a function.a. Global variableb. Local variablec. Hidden variabled. None of the above; you cannot create a variable inside a function
True or FalseA statement in one function can access a local variable in another function.
Write a function named max that accepts two integer values as arguments and returns the value that is the greater of the two. For example, if 7 and 12 are passed as arguments to the function, the
When an object is falling because of gravity, the following formula can be used to determine the distance the object falls in a specific time period:The variables in the formula are as follows: d is
What are the variables that receive pieces of data in a function called?
What does the following code display?numbers = [5, 4, 3, 2, 1, 0]print(numbers[:3])
Draw a flowchart showing the general logic for totaling the values in a list.
Design a program that asks the user to enter a series of 20 numbers. The program should store the numbers in a list then display the following data:• The lowest number in the list• The highest
What will the following code display?numbers = [1, 2, 3, 4, 5]print(numbers[−2])
This will happen if you try to use an index that is out of range for a list.a. A ValueError exception will occur.b. An IndexError exception will occur.c. The list will be erased and the program will
True or FalseA file object’s writelines method automatically writes a newline ('') after writing each list item to the file.
What does the following code display?numbers = [1, 2, 3, 4, 5, 6, 7, 8]print(numbers[−4:])
Write a function that accepts a list as an argument (assume the list contains integers) and returns the total of the values in the list.
If you have downloaded the source code from the Premium Companion Website you will find a file named charge_accounts.txt in the Chapter 07 folder. This file has a list of a company’s valid charge
How do you find the number of elements in a list?
This function returns the length of a list.a. Lengthb. Sizec. Lend. Lengtho
True or FalseYou can use the + operator to concatenate two lists.
What does the following code display?values = [2] * 5print(values)
Assume the names variable references a list of strings. Write code that determines whether 'Ruby' is in the names list. If it is, display the message 'Hello Ruby'. Otherwise, display the message 'No
In a program, write a function named roll that accepts an integer argument number_ of_throws. The function should generate and return a sorted list of number_of_throws random numbers between 1 and 6.
What will the following code display?numbers1 = [1, 2, 3]numbers2 = [10, 20, 30]numbers3 = numbers1 + numbers2print(numbers1)print(numbers2)print(numbers3)
When the * operator’s left operand is a list and its right operand is an integer, the operator becomes this.a. The multiplication operatorb. The repetition operatorc. The initialization operatord.
True or FalseA list can be an element in another list.
The local driver’s license office has asked you to create an application that grades the written portion of the driver’s license exam. The exam has 20 multiple-choice questions. Here are the
What will list1 and list2 contain after the following statements are executed?list1 = [1, 2] * 2list2 = [3]list2 += list1
What will the following code display?numbers1 = [1, 2, 3]numbers2 = [10, 20, 30]numbers2 += numbers1print(numbers1)print(numbers2)
This list method adds an item to the end of an existing list.a. Addb. Add_toc. Increased. Append
True or FalseYou can remove an element from a tuple by calling the tuple’s remove method.
Write a statement that creates a two-dimensional list with 5 rows and 3 columns. Then write nested loops that get an integer value from the user for each element in the list.
What will the following code display?numbers = [1, 2, 3, 4, 5]my_list = numbers[1:3]print(my_list)
Assume the following statement appears in a program:mylist = [ ] Which of the following statements would you use to add the string 'Labrador' to the list at index 0?a. Mylist[0] = 'Labrador'b.
What will the following code display?numbers = [1, 2, 3, 4, 5]my_list = numbers[:1]print(my_list)
The Lo Shu Magic Square is a grid with 3 rows and 3 columns, shown in Figure 7-18. The Lo Shu Magic Square has the following properties:• The grid contains the numbers 1 through 9 exactly.• The
If you call the index method to locate an item in a list and the item is not found, this happens.a. A ValueError exception is raised.b. An InvalidIndex exception is raised.c. The method returns
What will the following code display?numbers = [1, 2, 3, 4, 5]my_list = numbers[:]print(my_list)
This built-in function returns the highest value in a list.a. Highestb. Maxc. Greatestd. Best_of
What will the following code display?numbers = [1, 2, 3, 4, 5]my_list = numbers[−3:]print(my_list)
This file object method returns a list containing the file’s contents.a. To_listb. Getlistc. Readlined. Readlines
Write a program that simulates a Magic 8 Ball, which is a fortune-telling toy that displays a random response to a yes or no question. In the student sample programs for this book, you will find a
What will the following code display?names = ['Jim', 'Jill', 'John', 'Jasmine']if 'Jasmine' not in names:print('Cannot find Jasmine.')else:print("Jasmine's family:")print(names)
Many companies use telephone numbers like 555-GET-FOOD so the number is easier for their customers to remember. On a standard telephone, the alphabetic letters are mapped to numbers in the following
How do you find the length of a string?
This string method returns a copy of the string with all leading whitespace characters removed.a. Lstripb. Rstripc. Removed. Strip_leading
True or FalseWhen you call a string’s split method, the method divides the string into two substrings.
What does the following code display?name = 'joe'print(name.lower())print(name.upper())print(name)
Write a function that accepts a string as an argument and returns true if the argument starts with the substring 'https'. Otherwise, the function should return false.
If you have downloaded the source code from the Premium Companion Website you will find a file named text.txt in the Chapter 08 folder. The text that is in the file is stored as one sentence per
What is wrong with the following code?animal = 'Tiger'animal[0] = 'L'
This string method returns the lowest index in the string where a specified substring is found.a. First_index_ofb. Locatec. Findd. Index_of
Write code that makes a copy of a string with all occurrences of the lowercase letter 't' converted to uppercase.
If you have downloaded the source code you will find a file named text.txt in the Chapter 08 folder. Write a program that reads the file’s contents and determines the following:• The number of
What will the following code display?mystring = 'abcdefg'print(mystring[2:5])
This operator determines whether one string is contained inside another string.a. Containsb. Is_inc. ==d. In
Write a function that accepts a string as an argument and displays the string backwards.
What will the following code display?mystring = 'abcdefg'print(mystring[3:])
This string method returns true if a string contains only alphabetic characters and is at least one character in length.a. The isalpha methodb. The alpha methodc. The alphabetic methodd. The
Assume mystring references a string. Write a statement that uses a slicing expression and displays the first 3 characters in the string.
Write a program with a function that accepts a string as an argument and returns the number of vowels that the string contains. The application should have another function that accepts a string as
What will the following code display?mystring = 'abcdefg'print(mystring[:3])
Write code using the in operator that determines whether 'd' is in mystring.
What will the following code display?dct = {'Monday':1, 'Tuesday':2, 'Wednesday':3}print(dct['Tuesday'])
Write a statement that creates a dictionary containing the following key-value pairs:'a' : 1'b' : 2'c' : 3
Write a program that creates a dictionary containing the U.S. states as keys, and their capitals as values. (Use the Internet to get a list of the states and their capitals.) The program should then
Which part of a dictionary element must be immutable?
True or FalseDictionaries are not sequences.
What will the following code display?dct = {'Monday':1, 'Tuesday':2, 'Wednesday':3}print(dct.get('Monday', 'Not found'))
Suppose 'start' : 1472 is an element in a dictionary. What is the key? What is the value?
True or FalseA tuple can be a dictionary key.
What will the following code display?dct = {'Monday':1, 'Tuesday':2, 'Wednesday':3}print(dct.get('Friday', 'Not found'))
Showing 1 - 100
of 839
1
2
3
4
5
6
7
8
9