CS 1 Flashcards
(optional, not needed)On comparing, what is 0, A, a value?
(optional, not needed)What has a value of 48, 65, 97?
What is the result of 3/4?
(ignore when on this side)0.75
explain +=, such as x += 52
(ignore when on this side) += means it adds upon, x = x + 52
How can you take the value for a variable from the user via the input
(ignore when on this side) input()
such as inp = input()
What does ', \n, \t do?
How do you make new line, tab, and a single quote?
How do you import math to import all functions directly
(ignore when on this side) from math import *(must use dot-notation)
How would you import sqrt function only directly? and what is the function for square root
(ignore when on this side)from math import sqrt
sqrt()
(optional, not needed) How do you import the random function and what is the function for random and what do you need? How do you do randomint and to pick out of a list such as “[ ]”(uses different random function)
(ignore when on this side) import random
print(random.randint(5, 10))
print(random.randint(5, 10))
import random
t = [1, 2, 3]
print(random.choice(t))
print(random.choice(t))
what keyword must you use to indicate that this is a function defintion?
(ignore when on this side) def
(optional not needed)What is another way to print quotations?
(ignore when on this side) (f” “) like print(f”‘GeeksforGeeks’”)
What does math.ceil() do?
What math.(function) does:Round a number upward to its nearest integer:
Such as print(math.ceil(1.4)) = 2
and print(math.ceil(-5.3)) = -5
What does math.floor() do?
What math.(function) does: Round numbers down to the nearest integer
What does floor division // do?
What rounds the result down to the nearest whole number?
Such as:
x = 15
y = 2
print(x // y)
What does Modulus % do?
What gives the remainder or the number and gives the full number if can divide it?
(optional, not needed)How does Modulus % work with negative numbers?
(ignore when on this side) For EX: What is -7 mod 5?
Solution: To find -7 mod 5, we firstly find the largest number that is less than or equal to -7 and divisible by 5. That number is -10. Now, in order to get remainder subtract -10 from -7(-7 -(-10), which gives 3 that is the remainder.
Recap: find largest divisble number of the divisor, than substact first number by that number.