CSE 102 Exam 1 Study Guide

¡Supera tus tareas y exámenes ahora con Quizwiz!

In this lab problem we are requiring you to compute some arithmetic operations. The following equations estimate the calories burned when exercising (source): Men: Calories = ( (Age x 0.2017) — (Weight x 0.09036) + (Heart Rate x 0.6309) — 55.0969 ) x Time / 4.184 Women: Calories = ( (Age x 0.074) — (Weight x 0.05741) + (Heart Rate x 0.4472) — 20.4022 ) x Time / 4.184 Your program will input the user for age in years, weight in pounds, heart rate in beats per minute, and time in minutes, respectively. Your job is to output calories burned for men and women. Your prompts should be as follows: Enter age (years):, Enter weight (pounds):, Enter heart rate (beats per minute):, and Enter time (minutes):. The prompts must be EXACTLY as written, including the colon (:) character, or your test cases will fail. Since you are prompting the user for input, you should not enter anything into the (optional) input box below, but input your numbers after your prompts. Ex: If the input is: Enter age (years):49 Enter weight (pounds):155 Enter heart rate (beats per minute):148 Enter time (minutes):60 Then the output is: Men: 489.7772466539196 calories Women: 580.939531548757 calories

''' Men: Calories = ((Age x 0.2017) - (Weight x 0.09036) + (Heart Rate x 0.6309) - 55.0969) x Time / 4.184 ''' ''' Women: Calories = ((Age x 0.074) - (Weight x 0.05741) + (Heart Rate x 0.4472) - 20.4022) x Time / 4.184 ''' age_years = int(input("Enter age (years):")) weight_pounds = int(input("Enter weight (pounds):")) heart_rate = int(input("Enter heart rate (beats per minute):")) time_min = int(input("Enter time (minutes):")) men_cal = ((age_years * 0.2017) - (weight_pounds * 0.09036) + (heart_rate * 0.6309) - 55.0969) * time_min / 4.184 women_cal = ((age_years * 0.074) - (weight_pounds * 0.05741) + (heart_rate * 0.4472) - 20.4022) *time_min / 4.184 print(" Men:",men_cal, "calories") print(" Women:",women_cal, "calories")

If x = 1 and y = 2, what is x//y ?

0

Given a series of instructions in English, create the equivalent machine language instructions. The English instructions are as follows, in this order: Get a number from the user and store it in M[3] Get another number from the user and store it in M[4] Add the two numbers together and store the result in M[5] Display the result that is stored in M[5]. Assume the following: Binary Instruction English Instruction Memory Location Binary Representation 11 Add M[3] 011 01 Input M[4] 100 10 Output M[5] 101 Specify the four machine language instructions for the English instructions using eleven bits for each instruction.

01 011 000 000 01 100 000 000 11 101 011 100 10 101 000 000

If x = 1 and y = 1, what is x//y ?

1

A 1,000 x 1,000 computer monitor has 1,000 rows and 1,000 columns. How many pixels does the monitor

1 million (1,000,000)

Consider the following English statement: If you eat lots of fruit and exercise every day, you will be healthy. Assume the statement overall is true. We'll define the following propositions: p: You eat lots of fruit q: You exercise every day r: You are healthy In all of the following questions, type "True" if the proposition is guaranteed to be true, type "False" if the proposition is guaranteed to be false, and type "Unknown" if there is no way to tell the truth value from the information given. 1.If it turns out that p is false and q is true, what is the truth value of r? 2.If it turns out that r is false and q is true, what is the truth value of p? 3. If it turns out that p is false and q is false, what is the truth value of r? 4.If it turns out that r is true and q is true, what is the truth value of p?

1. Unknown 2.False 3.Unknown 4. Unknown

Consider the following English statement: If I get another bad lab score or I have to work another shift, I will NOT be able to go home for the weekend. Assume the statement overall is true. We'll define the following propositions: p: I get another bad lab score q: I have to work another shift r: I will be able to go home for the weekend In all of the following questions, type "True" if the proposition is guaranteed to be true, type "False" if the proposition is guaranteed to be false, and type "Unknown" if there is no way to tell the truth value from the information given. 1.If it turns out that p is true and q is false, what is the truth value of r? 2.If it turns out that r is false and p is false, what is the truth value of q? 3.If it turns out that p is false and q is false, what is the truth value of r?

1.False 2.Unknown 3.Unknown

A computer executes the following instructions in order and one at a time. What is the final value of m? Instr1: m = 2 Instr2: m = m + 2 Instr3: m = m * 3

12

According to Moore's Law, if a chip (IC) can contain 5,000 transistors in a given year, about how many transistors can a chip contain 10 years later?

160,000, using the assumption of number of chips doubling every two years.

Assume math.sqrt( 7 ) returns 2.6457513110645907. What is returned by int( math.sqrt( 7 ) ) ?

2

What is the value returned by 2 % 3 ?

2

What is printed by print(1+3/2*2)

4.0

A Python program has statement x = 4, then x = x + 1, then print(x). What character(s) is/are printed to the screen?

5

A CPU accesses 100 program instructions. Each memory access takes 5 ns. The memory can only hold 50 instructions. The first 50 instructions are already in memory. Replacing those 50 by the next 50 takes 400 ns. What is the total time?

900

high-level language

A programming language like Python that is designed to be easy for humans to read and write print()

The hardware component whose main purpose is to process data is the:

CPU

In the following English statement, indicate whether Inclusive OR or Exclusive OR is intended in the meaning: Soup or salad included with every entree.

Exclusive OR

In the following English statement, indicate whether Inclusive OR or Exclusive OR is intended in the meaning: The new Spartan T-shirts are available in green, white, or black.

Exclusive OR

You do not need to keep a backup copy of files on your OneDrive (SpartanDrive) because the system is 100% reliable and there is no chance for loss of data.

False

CPU

Hardware that rubs program instructions and controls other hardware

Moore's Law

IC's double in circuit capacity about every 2 years, y doubling n times = y x 2^n, same size chip becomes higher speed over the years

In the following English statement, indicate whether Inclusive OR or Exclusive OR is intended in the meaning: I need a 4.0 in CSE 102 or math to get into the business school.

Inclusive OR

In the following English statement, indicate whether Inclusive OR or Exclusive OR is intended in the meaning: It is important for everyone to take a class in music or art.

Inclusive OR

Given a series of instructions in English, create the equivalent assembly language instructions. The English instructions are as follows, in this order: Get a number from the user and store it in M[2] Get another number from the user and store it in M[3] Add the two numbers together and store the result in M[4] Display the result that is stored in M[4]. Specify the four Assembly language instructions for the English instructions using Add, Input, and/or Output

Input M[2] Input M[3] Add M[4] M[2] M[3] Output M[4]

Which of the following is not a means to open an Excel file?

Insert a flash drive containing the file you want to open and it will automatically open

machine language

Instructions in binary code (0s and 1s).

If a user wants to make the computer run faster, the user should increase the size of:

RAM

Stop

Start w/ 00

Input

Start w/ 01

Output

Start w/ 10

Add

Start w/ 11

A particular computer X has a clock frequency of 2 GHz. Another computer Y is nearly identical but has a clock frequency of 2.3 GHz. Which describes the most likely relevant difference?

Y is faster than X

+

addition, x+y

cache

additional small fast memory

float()

allows a real number with a decimal point to appear anywhere Ex: 98.6, .0072

shut the door

command

laser printer

contains a rotating ink drum that is electrostaticly charged by a laser

pixel

displayed text and images consists of rows and columns of colored dots, each dot a pixel

/

division, x/y

binary numbers

each memory location is composed of bits(1 and 0's), a processor a # using base 2 0 0 0 0 0 0 0 0 128 64 32 16 8 4 2 1

A(n) _____ computer is a computer inside another electrical device, like a TV or car.

embedded

%(modulo Operator)

evaluates the remainder of the division of 2 integer operands, EX: 23%10 =3

**

exponent, x**y

Mad Libs are activities that have a person provide various words, which are then used to complete a short story in unexpected (and hopefully funny) ways. Complete the program to read the needed values from input, that the existing output statement(s) can use to output a short story. Ex: If the input is Eric Chipotle 12 cars Then the output is: Eric went to Chipotle to buy 12 different types of cars

first_name=input("") generic_location = input("") whole_number = int(input("")) plural_noun = input("") print(first_name, 'went to', generic_location, 'to buy', whole_number, 'different types of', plural_noun)

id()

gives the value of an object's identity

memory

hardware, stores data, RAM

Solid-State Drive (SSD)

implements a drive, using a computer chip (with no moving parts) instead of a spinning disk to store data

Below is the definition of your problem that we are asking you to solve using the math module. Prompt the user for floating point numbers x, y and z. For the x value your you will the use the following prompt Enter x value:inside of your input statement. Using the same approach you will prompt the user for y and z. - Given three floating-point numbers x, y, and z, your job is to output - the **square root** of x, - the **absolute value** of (y minus z) , and - the **factorial** of (the **ceiling** of z). Example of a sample run: Enter x value:5 Enter y value:6.5 Enter z value:3.2 Then the expected output from these entries is: 2.23606797749979 3.3 24 Hint: For finding out the square root you will need to use math.sqrt(), you need to use the website recommended above to find out which functions to use in order to solve the rest of the lab problem.

import math x = float(input("Enter x value:")) y = float(input("Enter y value:")) z = float(input("Enter z value:")) print(math.sqrt(x),math.fabs(y-z),math.factorial(math.ceil(z)))

A particular computer has a separate keyboard and screen. A user presses a key, and a character appears on the screen. The pressed key was mostly likely first stored:

in a memory

In Python when we say that a data structure is immutable, what does that mean?

it cannot be modified

This problem requires you to prompt the user for some information, and apply simple arithmetic operation to generate an output. We all know that driving is expensive. So let's write a program to observe this. Your job is to prompt the driver for miles per gallon and gas price (in dollars) per gallon You should prompt the user with the words: Enter miles per gallon: at which time the users enters a number, and then Enter the gas price: at which time the user enters the second number. The prompts must be EXACTLY as written, including the colon (:) character, or your test cases will fail. Since you are prompting the user for input, you should not enter anything into the (optional) input box below, but input your numbers after your prompts. Both inputs should be read as float data type , and your program will output the gas cost for 10 miles, 50 miles, and 400 miles. Due to the way floating point numbers are internally stored, there can be some discrepancies with the precision of calculations depending on the order things are done. To prevent this from causing your submission to be marked incorrect, please calculate the cost in the following order: The miles increment (10, 50, or 400) multiplied by 1.0/miles per gallon multiplied by the gas price. Example: If the input is: Enter miles per gallon:20.0 Enter the gas price:3.1599 Then the output is: 1.57995 7.89975 63.198

milesper = float(input("Enter miles per gallon:")) gasprice = float(input("Enter the gas price:")) miles10 = 10 * (1.0 / milesper) * gasprice miles50 = 50 * (1.0 / milesper) * gasprice miles400 = 400 * (1.0 / milesper) * gasprice print(miles10, miles50, miles400)

*

multiplication, x*y

Given a series of instructions in English, create the equivalent high-level language instructions. The English instructions are as follows, in this order: Get a number from the user and store it in M[2] Get another number from the user and store it in M[3] Add the two numbers together and store the result in M[4] Display the result that is stored in M[4]. Specify the four high-level language instructions for the English instructions assuming the following: Use number1 for M[2] Use number2 for M[3] Use answer for M[4]

number1 = input() number2 = input() answer = number1+number2 print (answer)

truth table with three variables

p q r ( p ∨ r ) ∧ ¬q T T T F T T F F T F T T T F F T F T T F F T F F F F T T F F F F

pvq, p or q

p q= pvq t t=t t f= t f t=t f f= f

p ^ q, p and q

p q=p^q T T=T T F=F F T=F F F=F

if p then q

p->q, false if p is true and q is false

Write a program that prints a formatted "No parking" sign as shown below. Note the first line has two leading spaces. For ALL labs, end with newline (unless otherwise stated). NO PARKING 1:00 - 5:00 a.m.

print(" NO PARKING") print("1:00 - 5:00 a.m.")

Write a program that outputs "Hello World!" For ALL labs, end with newline (unless otherwise stated).

print("Hello World!")

type()

prints the type of object

10 is a prime number.

proposition

All politicians are dishonest

proposition

object

represents a value and is automatically created by the interpreter when executing a line of code

Write a program using integers usernum and x as input, and output usernum divided by x four times. You should prompt the user with the words: Enter the first integer: at which time the users enters a number, and then Enter the second integer: at which time the user enters the second number. The prompts must be EXACTLY as written, including the colon (:) character, or your test cases will fail. Since you are prompting the user for input, you should not enter anything into the (optional) input box below, but input your numbers after your prompts. Ex: If the input is: Enter the first integer: 2000 Enter the second integer: 2 Then the output is: 1000 500 250 125

second_int = "Enter the second integer: " usernum = int(input("Enter the first integer: ")) x = int(input(second_int)) usernum = usernum // x print(usernum, end= ' ') usernum = usernum // x print(usernum, end= ' ') usernum = usernum // x print(usernum, end= ' ') usernum = usernum // x print(usernum)

Hard Drive Disk (HDD)

spinning disk that stored bits using magnetism, older drive

Would you like some cake?

statement

A computer's drive _____ data when power is turned off.

stores

drive

stores data even after electricity is turned off

-

subtraction, -x+y, or x+-y

pvq=? p=t q=f

t

Assembly Language

textual human-understandable representation of a machine language's 0's and 1's Input Add Output

//

used to round doqn the resukt if a floating point to the closest whole number value Ex: 20//10= 2. 5.0//2= 2.0 (throw away remainder)

Write a program that takes a first name as the input, and outputs a welcome message to that name. Ex: If the input is Pat, the output is: Hello Pat and welcome to CS Online!

user_name = input() print('Hello',user_name, 'and welcome to CS Online!')


Conjuntos de estudio relacionados

Chapter 16-Nutritional Aspects of Pregnancy and Breastfeeding

View Set

"I know why the caged bird sings" Test Review.

View Set

AP Lang Unit 5 Progress Check MCQ Answers

View Set

Chapter 10 High-Risk Labor and Birth

View Set