Unit 1 Exam CS Principles

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/16

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

17 Terms

1
New cards

Why do we write comments?

To explain code and make it easier for humans to read.

2
New cards

How do we write comments?

Use # in Python to write a single-line comment.

3
New cards

What is a variable?

A named storage location that holds a value.

4
New cards

How do we format a variable to indicate that it is a constant?

Write the variable name in ALL CAPS.

5
New cards

Why is it useful to declare some variables as constants?

It makes the code clearer and prevents accidental changes.

6
New cards

What does this symbol (+) do when between two numbers?

It adds the numbers.

7
New cards

What does this symbol (+) do when between two strings?

It concatenates (joins) the strings.

8
New cards

What does this symbol (+) do when between a number and a string?

It causes an error because you can't add them directly.

9
New cards

What does the following code do: print("My favorite number is ", end='') print(9)

It prints My favorite number is 9 on one line without a space after the first part.

10
New cards

What does the following code do: print("It is\nnice to\nsee you.")

It prints text on multiple lines: "It is" / "nice to" / "see you."

11
New cards

What does * do when applied to a string?

It repeats the string that many times.

12
New cards

What does str() do? When might you use it?

It converts data into a string. Use it when printing numbers with text.

13
New cards

What do int() and float() do? When might you use them?

int() converts to an integer, float() converts to a decimal. Use them for math operations.

14
New cards

What does the comma do in console output?

It separates items and adds a space between them when printed.

15
New cards

What does type() do?

It shows the data type of a value or variable.

16
New cards

What is the syntax for the input function?

input("Prompt message: ")

17
New cards

The randint() method - how does it work?

It returns a random integer between two specified numbers (inclusive).