Computer Science: Test #2

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Reserved Words

(also called keywords) are special words with predefined meanings and syntax and are built into the programming language. Python recognizes these words and knows how to process them. We cannot use a keyword as a variable name, function name, or any other identifier.

What are the 4 types of program flow?

1. Sequential- runs top to bottom, in sequence 2. Branches- primarily the "if" statement 3. Loops (primarily the "for" and "while" loops 4. function calls (such as the print/input functions

What are the 5 rules for coders?

1. Think before you program- Formulas, Processing, Output should I produce? 2. A program is a human-readable essay on problem-solving that also happens to execute on a computer 3. The best way to improve your programming and problem-solving skills is PRACTICE. 4. We name things (such as variables) using technical naming conventions, but we try to do what we can to help the human readability of our code. 5. Test your code often and thoroughly.

What is the difference between a complier and interpreter?

A compiler and an interpreter do the same thing, just in different ways. Compliers convert all of the instructions into machine language ALL at once. Whereas, Interpreters convert one line of code at a time.

What is the IPO model?

A widely used approach in systems analysis and software engineering for describing the structure of an information processing program/other processes. We can also use this model to describe the process of problem-solving. This includes solving a problem by coding a solution or solving an everyday problem in real life.

Sometimes we need to ask the user to assign some value to the variable-

For this purpose, we use the following statement to prompt the user for a value to assign to a variable. We use the input function to do this type of assignment.

What is the significance of conditional to program flow?

In a conditional type of program flow, some steps are conditional, meaning they may be skipped completely depending on whether the condition presented is true of false.

What is special about the data that is received from an input function? What is a characteristic of the user's input?

It is always initially stored as a string value. It must be converted to a number before it can be used in a mathematical calculation. We capture the value from the user after the prompt and then immediately convert the string into a number in the same line of code.

What is Python?

Python is an interpreted, high-level and general-purpose programming language.

Assignment statement: assigns the string value Statesmen to the variable RBC_mascot.

RBC_mascot = 'statesmen'

What are Technical Naming Conventions?

They can be long/short as you want. They can contain letters/numbers, but cannot start with a number. A variable name can only contain alphanumeric characters and the underscore such as (a-z,A-Z,0-9, and __) They are case sensitive The underscore is legal and is typically used to separate words in multiple word variables... stay away from spaces. You cannot use one of Python's reserved words as a variable name.

What is another way to make your programs more readable?

Use comments. Comment lines are used to explain something that is going on in the code. A comment is a line that begins with a # character. Python ignores the content of a line starting with a hashtag. Used for clarity and human readability.

Loop structures programming

a condition is evaluated, and as long as the result is true, the program continues to execute a block of code. When the condition evaluates false or the number of specific iterations is met, the program exits the loop and continues.

What is a program?

an algorithm or sequence of steps that are executed in the order they were received by a computer processor.

Function calls programming

cause the program to pause momentarily while the function is executed and then once the function is done, Python continues with the next line.

Input function: Write an input function that prompts the user for the the number of hours in a day.

hours = int ( input 'How many hours are in a day?' )

What does IPO stand for?

input, process, output

An expression

is a basic sentence in Python that creates a new value or changes an existing value. Example x = 4 is a statement, x + 5 is an expression.

Statement

is a logical instruction that the interpreter can process. It does not actually do anything to change or manipulate a value but it is used to assign a value to a variable

A Variable

is a named place in memory where a programmer can store the date and later retrieve the data using the variable name. The name is a pointer that points to the unique location in memory that contains the value.

Sequential Programming

most of the time programs are sequential. very straight forward line by line, top to bottom, in order

Print Function: Write a print statement that will display 'I love programming'

print ( 'I love programming!' )

branched programming

some condition is evaluated, if true, the program takes one course and statements are executed, if false, another direction with different execution.

Fixed Values

such as numbers, integers, letters, and strings are called constants. This is because their value does not change throughout the program. A constant is usually assigned in the program and is a set value. x=7 where 7 is a constant. the assigned constant can only change if the programmer changes it by reassignment or with an expression.


Ensembles d'études connexes

Chapter 48: Assessment and Management of Patients with Obesity

View Set

PHIL 130 Final Exam UTK Dr. Moore

View Set

The Chinese Exclusion Act (1882)

View Set

Life Policy Provisions, Riders, and Options

View Set

Music History Listening Examples Quiz 3

View Set