IT 116 Ungraded Quizzes (13-19)

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

What are the two things that make up a pathname?

path to the file (location) and name of file

What two pieces of information do you need to give the open function as arguments?

pathname and access mode

What is a file?

a linear arrangement of data on a storage medium

What does the method used to return a single line of a file return when it reaches the end of the file?

the empty string

What type of loop do we use to read records?

a while loop

What does the append access mode do to a file?

adds to the bottom of the file

What appears after return in a return statement?

an expression

What is the name of the special line we use to run a Python program without directly calling the interpreter?

the hashbang line

Where must the hashbang appear?

the very first line of the script.

What are the two things that uniquely specify a file?

name and location

Are the series of number created by the functions in the random module really random?

no. they are a psedorandom number sequence

What is the range of numbers created by the random function of the random module.

0 to 1.0

What are the first two characters of the hasbang line?

#!

What is the name of the program that we use to run Python scripts?

Python3

What must you create to work with a file in Pythin?

a file object

What must you do if you have read the entire contents of a file and now want to read it again>

close the file and open it again for reading

What two things does the open function do?

creates a file object and returns a reference to it

Write the Python function get_positive which takes no parameter and returns a number greater than 0. This function should use the input function to ask the user for a number and convert it to an integer.It should then keep looping until it gets a number that is greater than 0. When it gets such a number, it should return that number.

def get_positive(): number = int(input("Integer greater than 0: ")) while num <= 0: print(number, "is not greater than 0") number = int(input("Integer greater than 0: ")) return number

What the individual pieces of data in a record called?

fields

What Python statement should I write when I am finished using the file variable file.write?

file.close()

If I have a variable named file, what is the Python statement I would write to write the work "hello" to the file?

file.write("hello")

Write a for loop which reads in integers stored in a file to which you have read access through the scores_file and adds them to the accumulator variable total.

for line in scores_file: total += int(line)

What is the Python function that creates the thing you need to work with a file?

open

If you wanted to use the functions in the math module inside your script, what statement should appear at the top of the script?

import math

If you wanted to use the functions in the random module inside your script, what statement should appear at the top of the script?

import random

If you wanted to read a single line of a file for which you had the file variable scores_file and store it in the variable line what Python statement would you write?

line = scores_file.readline()

Write the function call that will return the ceiling of the value 5.1 using the ceil function in the math module

math.ceil(5.1)

Write the function call that will return the floor of the value 5.6 using the floor function in the math module.

math.floor(5.6)

Write a function call that will return the value of the sine of π(pi). the sine function in the math module is sin

math.sin(math.pi)

if you wanted to print the value of pi from the math module, what statement would you use?

print(math.pi)

If you wanted to simulate the throw of a die using the randint function of the random module, what would you use as the function call.

random.randint(1,7)

What permissions does an account need on a Python script to be able to run it without typing the name of the Python interpreter on the command line?

read and execute permission

What are the three ways you can open a file?

reading, writing, appending

If you had the file variable scores_file and you wanted to get all the data in the file and store it in the variable results what Python statement would you write?

results = scores_file.read()

Write a single Python statement you would use to return the value of the expression interest * principle from within a function.

return interest * principle

Write a single Python statement to return True if the parameter number were less than 0, but otherwise return False.

return number < 0

Write a single Python statement you would use to return True if the parameter number_1 were equal to the paramter number_2, but otherwise return False.

return number_1 == number_2

Write the single Python statement you would use to return True if the parameter number_1 were greater than the parameter number_2, but otherwise return False.

return number_1 > number_2

Write the Python statement that would create a file object for the file scores.txt for appending and assign it to the variable scores_file

scores_file = open("scores.txt", "a")

Write the Python statement that would create a file object for the file scores.txt for writing and assign it to the variable scores_file

scores_file = open("scores.txt", "w")

If you wanted to write "78" to a file for which you had the file variable scores_file what Python statement would you write?

scores_file.write("78")

Write a Python statement that would create a file object for the file scores.txt for reading and assign it to the variable scores_file.

scores_files = open("scores.txt", "r")

What do you call the initial value given to an algorithm used to generate "random" numbers.

seed

What is the string method that can be used to remove leading and trailing whitespace from a string?

strip

What must follow #! in a hasbang line? I don't want the actual value, I want you to tell to describe what it is.

the absolute pathname of the Python interpreter

What is a record?

the complete set of data about some event or thing


Set pelajaran terkait

Adobe Visual Design Certification Review

View Set

Simulation Lab 12.1: Module 12 Work with Data in Event Viewer

View Set

Chapter 30: Hematologic Problems tbnk

View Set

Night, Chapter 6, Study Questions

View Set

2023Grade5Chapter12ElijahTakenToHeavenAndElisha

View Set

Operations Management Exam 1 Rutgers ELY

View Set

AP Psychology Chapter 1 Applied Questions

View Set