CS 10 Unit 2 Flashcards
What are the three aspects for an if statement in python?
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
True or false, an if statement can only have one line of execution
False, it can have multiple (ex:
If condition(true):
condition
condition
condition
True or false, the actions are skipped if the boolean value is false
True, if it is false, then the conditions after the if statement won’t run
What are all the different comparison operators
==, <=, >=, !=, <, > (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)
What are examples of the not function, the boolean or boolean statement, and the boolean and boolean statement
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)
Why is a namespace useful?
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 to get a size of a string in C++
You do variable of the string name period size();
How do you print out “Hello World!”
include <iostream></iostream>
int main() {
std::cout «_space;“Hello, World!” «_space;std::endl;
return 0;
}
How do you print out “Hello World!” while using the std namespace (which is actually built in C++)
include <iostream></iostream>
using namespace std;
int main() {
cout «_space;“Hello World!” «_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