New Semester
Started
Get
50% OFF
Study Help!
--h --m --s
Claim Now
Question Answers
Textbooks
Find textbooks, questions and answers
Oops, something went wrong!
Change your search query and then try again
S
Books
FREE
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
Tutors
Online Tutors
Find a Tutor
Hire a Tutor
Become a Tutor
AI Tutor
AI Study Planner
NEW
Sell Books
Search
Search
Sign In
Register
study help
computer science
starting out with python
Starting Out With Python Global Edition 4th Edition Tony Gaddis - Solutions
What are the advantages of breaking a large program into modules?
Is it permissible for a local variable in one function to have the same name as a local variable in a different function?
Write a program that generates printable addition tests. The tests should consist of 5 questions which present a simple addition question in the following format, where the question number goes from 1 to 5, and num1 and num2 are randomly generated numbers between 1 and 10:The program should simply
This standard library function returns a random integer within a specified range of values.a. Randomb. Randintc. Random_integerd. Uniform
True or FalseA function in Python can return more than one value.
What is a parameter variable’s scope?
This standard library function returns a random floating-point number in the range of 0.0 up to 1.0 (but not including 1.0).a. Randomb. Randintc. Random_integerd. Uniform
True or FalseIPO charts provide only brief descriptions of a function’s input, processing, and output, but do not show the specific steps taken in a function.
Write a program that asks the user to enter five test scores. The program should display a letter grade for each score and the average test score. Write the following functions in the program:• Calc_average. This function should accept five test scores as arguments and return the average of the
When a parameter is changed, does this affect the argument that was passed into the parameter?
This standard library function returns a random floating-point number within a specified range of values.a. Randomb. Randintc. Random_integerd. Uniform
In this chapter, you saw an example of how to write an algorithm that determines whether a number is even or odd. Write a program that generates 100 random numbers and keeps a count of how many of those random numbers are even, and how many of them are odd.
The following statements call a function named show_data. Which of the statements passes arguments by position, and which passes keyword arguments?a. Show_data(name='Kathryn', age=25)b. Show_data('Kathryn', 25)
A prime number is a number that is only evenly divisible by itself and 1. For example, the number 5 is prime because it can only be evenly divided by 1 and 5. The number 6, however, is not prime because it can be divided evenly by 1, 2, 3, and 6. Write a Boolean function named is_prime which takes
What is the scope of a global variable?
This is a design tool that describes the input, processing, and output of a function.a. Hierarchy chartb. IPO chartc. Datagram chartd. Data processing chart
This exercise assumes that you have already written the is_prime function in Programming Exercise 17. Write another program that displays all of the prime numbers from 1 to 100. The program should have a loop that calls the is_prime function.Exercise 17A prime number is a number that is only evenly
Give one good reason that you should not use global variables in a program.
This type of function returns either True or False.a. Binaryb. True_falsec. Booleand. Logical
Suppose you have taken out a loan for a certain amount of money with a fixed monthly interest rate and monthly payments, and you want to determine the monthly payment amount necessary to pay off the loan within a specific number of months. The formula is as follows:The terms in the formula are:•
What is a global constant? Is it permissible to use global constants in a program?
This is a math module function.a. Derivativeb. Factorc. Sqrtd. Differentiate
Write a program that generates a random number in the range of 1 through 100, and asks the user to guess what the number is. If the user’s guess is higher than the random number, the program should display “Too high, try again.” If the user’s guess is lower than the random number, the
How does a value-returning function differ from the void functions?
Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows:1. When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. If the number is 2, then
Write a function named triangle that uses the turtle graphics library to draw a triangle. The functions should take arguments for the X and Y coordinates of the triangle’s vertices, and the color with which the triangle should be filled. Demonstrate the function in a program.
What is a library function?
Write a program that uses turtle graphics to display a snowman, similar to the one shown in Figure 5-30. In addition to a main function, the program should also have the following functions:• DrawBase. This function should draw the base of the snowman, which is the large snowball at the
Why are library functions like “black boxes”?
In a program, write a function named drawPattern that uses the turtle graphics library to draw the rectangular pattern shown in Figure 5-31. The drawPattern function should accept two arguments: one that specifies the pattern’s width, and another that specifies the pattern’s height. (The
What does the following statement do?x = random.randint(1, 100)
Write a turtle graphics program that uses the square function presented in this chapter, along with a loop (or loops) to draw the checkerboard pattern shown in Figure 5-32. Figure 5-32 Checkerboard pattern
What does the following statement do?print(random.randint(1, 20))
Write a turtle graphics program that draws a city skyline similar to the one shown in Figure 5-33. The program’s overall task is to draw an outline of some city buildings against a night sky. Modularize the program by writing functions that perform the following tasks:• Draw the outline of
What does the following statement do?print(random.randrange(10, 20))
What does the following statement do?print(random.random())
What does the following statement do?print(random.uniform(0.1, 0.5))
When the random module is imported, what does it use as a seed value for random number generation?
What happens if the same seed value is always used for generating random numbers?
What is the purpose of the return statement in a function?
Look at the following function definition:def do_something(number):return number * 2a. What is the name of the function?b. What does the function do?c. Given the function definition, what will the following statement display?print(do_something(10))
What is a Boolean function?
What import statement do you need to write in a program that uses the math module?
Write a statement that uses a math module function to get the square root of 100 and assigns it to a variable.
Write a statement that uses a math module function to convert 45 degrees to radians and assigns the value to a variable.
What is an output file?
A file that data is written to is known as a(n) ____________.a. Input fileb. Output filec. Sequential access filed. Binary file
True or FalseWhen working with a sequential access file, you can jump directly to any piece of data in the file without reading the data that comes before it.
Describe the three steps that must be taken when a file is used by a program.
Write a program that opens an output file with the filename things.txt, writes the name of an animal, a fruit, and a country to the file on separate lines, then closes the file.
Assume a file containing a series of integers is named numbers.txt and exists on the computer’s disk. Write a program that displays all of the numbers in the file.
What is an input file?
A file that data is read from is known as a(n) ____________.a. Input fileb. Output filec. Sequential access filed. Binary file
True or FalseWhen you open a file that file already exists on the disk using the 'w' mode, the contents of the existing file will be erased.
What three steps must be taken by a program when it uses a file?
Before a file can be used by a program, it must be ____________.a. Formattedb. Encryptedc. Closedd. Opened
True or FalseThe process of opening a file is only necessary with input files. Output files are automatically opened when data is written to them.
In general, what are the two types of files? What is the difference between these two types of files?
True or FalseWhen an input file is opened, its read position is initially set to the first item in the file.
Which mode should a file be opened in to allow data to be written to it, erasing any previous data?Previous dataWhat is a file’s read position? Where is the read position when a file is first opened for reading?
Assume that a file named scores.txt exists on the computer’s disk. It contains a series of records, each with two fields – a name, followed by a score (an integer between 1 and 100). Write a program that displays the name and score of the record with the highest score, as well as the number of
What are the two types of file access? What is the difference between these two?
The contents of this type of file can be viewed in an editor such as Notepad.a. Text fileb. Binary filec. English filed. Human-readable file
True or FalseWhen a file that already exists is opened in append mode, the file’s existing contents are erased.
If a file does not exist and a program attempts to open it in append mode, what happens?
Modify the code that you wrote in problem 4 so it adds all of the numbers read from the file and displays their total.
Assume a file containing a series of integers is named numbers.txt and exists on the computer’s disk. Write a program that reads all of the numbers stored in the file and calculates their total.
When writing a program that performs an operation on a file, what two fileassociated names do you have to work with in your code?
This type of file contains data that has not been converted to text.a. Text fileb. Binary filec. Unicode filed. Symbolic file
True or FalseIf you do not handle an exception, it is ignored by the Python interpreter, and the program continues to execute.
Write code that opens an output file with the filename number_list.txt, but does not erase the file’s contents if it already exists.
Assume a file containing a series of integers is named numbers.txt and exists on the computer’s disk. Write a program that calculates the average of all the numbers stored in the file.
If a file already exists, what happens to it if you try to open it as an output file (using the 'w' mode)?
When working with this type of file, you access its data from the beginning of the file to the end of the file.a. Ordered accessb. Binary accessc. Direct accessd. Sequential access
What is a record? What is a field?
Describe the way that you use a temporary file in a program that modifies a record in a sequential access file.
Describe the way that you use a temporary file in a program that deletes a record from a sequential file.
What type of exception does a program raise when it tries to open a nonexistent file?
What will the following code display? numbers = [1, 2, 3, 4, 5] numbers [2] = 99 print (numbers)
What type of exception does a program raise when it uses the float function to convert a non-numeric string to a number?
This term refers to an individual item in a list.a. Elementb. Binc. Cubbyholed. Slot
True or FalseLists in Python are immutable.
Look at the following statement:numbers = [10, 20, 30, 40, 50]a. How many elements does the list have?b. What is the index of the first element in the list?c. What is the index of the last element in the list?
Write a statement that uses the list and range functions to create a list of the numbers from 1 to 100.
Design a program that uses a loop to build a list named valid_numbers that contains only the numbers between 0 and 100 from the numbers list below. The program should then determine and display the total and average of the values in the valid_numbers list.numbers = [74, 19, 105, 20, −2, 67, 77,
What will the following code display?numbers = list(range(3))print(numbers)
This is a number that identifies an item in a list.a. Elementb. Indexc. Bookmarkd. Identifier
True or FalseTuples in Python are immutable.
Look at the following statement:letters = ['A', 'B', 'C', 'D']a. What value is stored in letters[1]?b. What value is stored in letters[3]?c. What value is stored in letters[−2]?
Assume names references a list. Write a for loop that displays each element of the list.
True or FalseThe del statement deletes an item at a specified index in a list.
What will the following code display?values = [2, 4, 6, 8, 10]print(values[1:3])
Assume scores is a list of randomly-ordered numbers between 0 and 100. Write code that sorts the list, reverses the order of the items in the list, and prints the biggest value in the list.
Design a program that lets the user enter the total rainfall for each of 12 months into a list. The program should calculate and display the total rainfall for the year, the average monthly rainfall, the months with the highest and lowest amounts.
What will the following code display?numbers = list(range(1, 10, 2))for n in numbers:print(n)
This is the last index in a list.a. 1b. 99c. 0d. The size of the list minus one
True or FalseAssume list1 references a list. After the following statement executes, list1 andlist2 will reference two identical but separate lists in memory:list2 = list1
Design a program that generates a seven-digit lottery number. The program should generate seven random numbers, each in the range of 0 through 9, and assign each number to a list element. (Random numbers were discussed in Chapter 5.) Then write another loop that displays the contents of the list.
This is the first index in a list.a. −1b. 1c. 0d. The size of the list minus one
What will the following code display?numbers = [10] * 5print(numbers)
Showing 200 - 300
of 837
1
2
3
4
5
6
7
8
9
Step by Step Answers