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 Study Help
New
Search
Search
Sign In
Register
study help
computer science
starting out with python
Questions and Answers of
Starting Out With Python
What is the index of the first character in a string?
This is the last index in a string.a. 1b. 99c. 0d. The size of the string minus one
True or FalseYou can use the for loop to iterate over the individual characters in a string.
What does the following code display?mystr = 'abc' * 3print(mystr)
Write a program that reads a string from the user containing a date in the form mm/dd/yyyy. It should print the date in the format March 12, 2018.
If a string has 10 characters, what is the index of the last character?
This will happen if you try to use an index that is out of range for a string.a. A ValueError exception will occur.b. An IndexError exception will occur.c. The string will be erased and the program
True or FalseThe isupper method converts a string to all uppercase characters.
What will the following code display?mystr = 'abracadabra'print(mystr[6:9])
Write a loop that counts the number of alphanumeric characters (letters or digits) that appear in the string referenced by mystring.
What happens if you try to use an invalid index to access a character in a string?
This function returns the length of a string.a. Lengthb. Sizec. Lend. Lengthof
True or FalseThe repetition operator (*) works with strings as well as with lists.
To play the PowerBall lottery, you buy a ticket that has five numbers in the range of 1–69, and a “PowerBall” number in the range of 1–26. (You can pick the numbers yourself, or you can let
What does the following code display?numbers = [1, 2, 3, 4, 5, 6, 7]print(numbers[4:6])
In the student sample program files for this chapter, you will find a text file named GasPrices.txt. The file contains the weekly average prices for a gallon of gas in the United States, beginning on
Assume the variable big references a string. Write a statement that converts the string it references to lowercase and assigns the converted string to the variable little.
A “Caesar Cipher” is a simple way of encrypting a message by replacing each letter with a letter a certain number of spaces up the alphabet. For example, if shifting the message by 13 an A would
Write a program that creates a dictionary containing the names of the Galilean moons of Jupiter as keys and their mean radiuses (in kilometers) as values. The dictionary should contain the following
Assume the following statement appears in a program:days = 'Monday Tuesday Wednesday'Write a statement that splits the string, creating the following list:['Monday', 'Tuesday', 'Wednesday']
Assume the following statement appears in a program:values = 'one$two$three$four'Write a statement that splits the string, creating the following list:['one', 'two', 'three', 'four']
An element in a dictionary has two parts. What are they called?
You can use the _________ operator to determine whether a key exists in a dictionary.a. &b. inc. ˆd. ?
True or FalseThe keys in a dictionary must be mutable objects.
What is the output of the following code?ch = 'a'ch2 = ch.upper()print(ch, ch2)
What will the following code display?var = '$'print(var.upper())
Assume each of the variables set1 and set2 references a set. Write code that creates another set containing all the elements of set1 and set2, and assigns the resulting set to the variable set3.
In this chapter’s source code folder (available on the Premium Companion Website at www.pearsonglobaleditions.com/gaddis), you will find a text file named WorldSeriesWinners. txt. This file
True or FalseThe following statement creates an empty set:myset = ()
Previously in this chapter you saw the card_dealer.py program that simulates cards being dealt from a deck. Enhance the program so it simulates a simplified version of the game of Blackjack between
After the following statement executes, what elements will be stored in the myset set?myset = set(10)
What does the items method return?
Write a program that keeps vegetable names and prices in a dictionary as key-value pairs. The program should display a menu that lets the user see a list of all vegetables and their prices, add a new
True or FalseThe dictionary method popitem does not raise an exception if it is called on an empty dictionary.
How do you delete an element from a dictionary?
Write code to create a set with the following strings as members: “rock”, “scissors”, “paper”.
Write a program that reads the contents of two text files and compares them in the following ways:• It should display a list of all the unique words contained in both files.• It should display a
How can you determine whether a key-value pair exists in a dictionary?
The _________ method returns the value associated with a specified key and removes that key-value pair from the dictionary.a. Pop()b. Random()c. Popitem()d. Rand_pop()
True or FalseThe following statement creates an empty dictionary:mydct = {}
How do you determine the number of elements that are stored in a dictionary?
Assume each of the variables set1 and set2 references a set. Write code that creates another set containing only the elements that are found in both set1 and set2, and assigns the resulting set to
Suppose a dictionary named inventory exists. What does the following statement do?del inventory[654]
The _________ dictionary method returns the value associated with a specified key. If the key is not found, it returns a default value.a. Pop()b. Key()c. Value()d. Get()
What will the following code display?dct = {0:[1, 2, [3, 4], 5]}print(dct[0][2][1])
Assume each of the variables set1 and set2 references a set. Write code that creates another set containing the elements that appear in set1 but not in set2, and assigns the resulting set to the
What will the following code display?stuff = {1 : 'aaa', 2 : 'bbb', 3 : 'ccc'}print(len(stuff))
The _________ method returns all of a dictionary’s keys and their associated values as a sequence of tuples.a. Keys_values()b. Values()c. Items()d. Get()
True or FalseSets store their elements in an unordered fashion.
What values will the following code display? (Don’t worry about the order in which they will be displayed.)dct = {1:[0, 1], 2:[2, 3], 3:[4, 5]}for k in dct:print(k)
Assume each of the variables set1 and set2 references a set. Write code that creates another set containing the elements that appear in set2 but not in set1, and assigns the resulting set to the
What will the following code display?stuff = {1 : 'aaa', 2 : 'bbb', 3 : 'ccc'}for k in stuff:print(k)
Write a program that reads the contents of a text file. The program should create a dictionary in which the key-value pairs are described as follows:• Key. The keys are the individual words found
The following function returns the number of elements in a set:a. Size()b. Len()c. Elements()d. Count()
True or FalseYou can store duplicate elements in a set.
After the following statement executes, what elements will be stored in the myset set?myset = set('Saturn')
Assume that set1 references a set of integers and set2 references an empty set. Write code that iterates through each element of set1. If the element is greater than 100, add it to set2.
What is the difference between the dictionary methods pop and popitem?
You can add one element to a set with this method.a. Appendb. Addc. Updated. Merge
True or FalseThe remove method raises an exception if the specified element is not found in the set.
Assume the variable dct references a dictionary. Write code that pickles the dictionary and saves it to a file named mydata.dat.
You can add a group of elements to a set with this method.a. Appendb. Addc. Updated. Merge
After the following statement executes, what elements will be stored in the myset set?myset = set('a bb ccc dddd')
Write code that retrieves and unpickles the dictionary that you pickled in Algorithm Workbench 11.
What does the keys method return?
This set method removes an element, but does not raise an exception if the element is not found.a. Removeb. Discardc. Deleted. Erase
After the following statement executes, what elements will be stored in the myset set?myset = set([2, 4, 4, 6, 6, 6, 6])
What does the values method return?
This set method removes an element and raises an exception if the element is not found.a. Removeb. Discardc. Deleted. Erase
By doing this, you can hide a class’s attribute from code outside the class.a. Avoid using the self parameter to create the attributeb. Begin the attribute’s name with two underscoresc. Begin the
Write a class named Employee that holds the following data about an employee in attributes: name, ID number, department, and job title.Once you have written the class, write a program that creates
True or FalseA class method does not have to have a self parameter.
The following statement calls an object’s method. What is the name of the method? What is the name of the variable that references the object?wallet.get_dollar()
When the _ _init_ _ method executes, what does the self parameter reference?
True or FalseStarting an attribute name with two underscores will hide the attribute from code outside the class.
In this chapter, we use the metaphor of a cookie cutter and cookies that are made from the cookie cutter to describe classes and objects. In this metaphor, are objects the cookie cutter, or the
Write a class named Patient that has attributes for the following data:• First name, middle name, and last name• Address, city, state, and ZIP code• Phone number• Name and phone number of
A(n) ______________ method gets the value of a data attribute but does not change it.a. Retrieverb. Constructorc. Mutatord. Accessor
True or FalseYou cannot directly call the _ _str_ _ method.
In a Python class, how do you hide an attribute from code outside the class?
What is the purpose of the _ _init_ _ method? When does it execute?
A(n) ______________ method stores a value in a data attribute or changes its value in some other way.a. Modifierb. Constructorc. Mutatord. Accessor
The _ _str_ _ method in Python returns a string representation of an object’s state. Describe how the _ _str_ _ method is used to print the state of an object.
This exercise assumes you have created the Employee class for Programming Exercise 4. Create a program that stores Employee objects in a dictionary. Use the employee ID number as the key. The program
What is the purpose of the self parameter in a method?
This exercise assumes you have created the RetailItem class for Programming Exercise 5. Create a CashRegister class that can be used with the RetailItem class. The CashRegister class should be able
The ______________ method is automatically called when an object is created.a. _ _init_ _b. initc. _ _str_ _d. _ _object_ _
In a Python class, how do you hide an attribute from code outside the class
If a class has a method named _ _str_ _, which of these is a way to call the method?a. You call it like any other method: object._ _str_ _()b. By passing an instance of the class to the built in str
In this programming exercise, you will create a simple trivia game for two players. The program will work like this:• Starting with player 1, each player gets a turn at answering 5 trivia
What is the purpose of the _ _str_ _ method?
A set of standard diagrams for graphically depicting object-oriented systems is provided by ______________.a. The Unified Modeling Languageb. Flowchartsc. Pseudocoded. The Object Hierarchy System
How do you call the _ _str_ _ method?
In one approach to identifying the classes in a problem, the programmer identifies the ______________ in a description of the problem domain.a. Verbsb. Adjectivesc. Adverbsd. Nouns
What is an instance attribute?
In one approach to identifying a class’s data attributes and methods, the programmer identifies the class’s ______________.a. Responsibilitiesb. Namec. Synonymsd. Nouns
A program creates 10 instances of the Coin class. How many _ _sideup attributes exist in memory?
The typical UML diagram for a class has three sections. What appears in these three sections?
In this section, we discussed superclasses and subclasses. Which is the general class, and which is the specialized class?
True or FalsePolymorphism allows you to write methods in a subclass that have the same name as methods in the superclass.
Showing 600 - 700
of 839
1
2
3
4
5
6
7
8
9