CS 10 Unit 2 Flashcards

1
Q

What are the three aspects for an if statement in python?

A

It is a decision structure, it can cause an execution to have more than one path of executions(if true, then you do this, if false, then do this(else)), and what is executed is determined by the boolean values that goes into the statements

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

True or false, an if statement can only have one line of execution

A

False, it can have multiple (ex:
If condition(true):
condition
condition
condition

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

True or false, the actions are skipped if the boolean value is false

A

True, if it is false, then the conditions after the if statement won’t run

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are all the different comparison operators

A

==, <=, >=, !=, <, > (keep in mind that it’s not =<, it’s <= (the greater or less than sign first), just read it from left to right and then it will make sense)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are examples of the not function, the boolean or boolean statement, and the boolean and boolean statement

A

temp = 9
if not(temp > 10):
print(“True”) (only do semicolon in c++)

if temp > 5 and temp < 10:
print(“True”)

if temp > 5 or temp < 6:
print(“True”) (don’t need paranthesis)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Why is a namespace useful?

A

If you have two of the same variable names in different namespaces, you reduce confusion for which one is which because you can put the namespace::variable name or whatever (some format like that)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How to get a size of a string in C++

A

You do variable of the string name period size();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you print out “Hello World!”

A

include <iostream></iostream>

int main() {
std::cout &laquo_space;“Hello, World!” &laquo_space;std::endl;
return 0;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you print out “Hello World!” while using the std namespace (which is actually built in C++)

A

include <iostream></iostream>

using namespace std;

int main() {
cout &laquo_space;“Hello World!” &laquo_space;endl
return 0;
// you always have to return an integer
}
// you do not have to include the namespace std before this, as you specified in the second line that you are using the namespace

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly