What is the following output?
print(not True and False or True)
print(not True or False and True)
True
False
What is the difference between the following codes?
print("six" + "seven")
print("six", "seven")
print("six" + "seven") outputs "sixseven".
print("six", "seven") outputs "six seven" with space.
What is the output of the following code?
pt = [["H","He"],["Li","Be","B","C","N","O","F","Ne"]]
print(pt[1][2])
What is the result of the following expression?
print(4+125%40*2//4**2-1)
3
Find a, b, c, d.
str = "sly fox jumped over the lazy dog"
print(str[a:b] + str[c:d])
OUT: "overjumped"
a=15, b=19, c=8, d=14
EXAMPLE: N = 5, X = [2, 5, -1, 3.5, 4], R = 6
x_min = X[0]
x_max = X[0]
for i in range(1, N):
if X[i] > x_max:
x_max = X[i]
if X[i] < x_min:
x_min = X[i]
print(x_max - x_min)
Rank the following operations from highest to lowest priority, assuming no parentheses. State which operations have the same priority.
+ % // - * ** /
Highest: **
Middle: % // * / they have the same priority
Low: + -
Create a for loop that prints the Mth character of a string X with N characters.
SAMPLE INPUT 1: X="hello world!", N = 12, M = 3
SAMPLE OUTPUT 1: "l r!"
SAMPLE INPUT 2: X="fourth july", N = 11, M =4
SAMPLE OUTPUT 2: "rj"
Sample code.
for i in range(M-1, N, M):
print(X[i], end="")
Create a list Y of the next N fibonacci numbers, given two starting numbers A and B. (Each number is the sum of the previous two numbers).
EXAMPLE: N = 4, A = 1, B = 2, Y = [3, 5, 8, 13]
Y = []
for _ in range(N):
A, B = B, A + B
Y.append(B)
print(Y)
What is the result of the following?
print(7 ** (77) % 10-3)
4
String s = "xooxox". How many unique non-empty substrings s[a:b] exist, where a and b are integers?
2+3+4+3+2+1 = 15
Given a list of numbers, L1, with size N, create a sorting algorithm that stores the sorted array in L2.
EXAMPLE: N = 4, L1 = [3, -1, 2, 8], L2 = [-1, 2, 3, 8]
Answers may vary
NOT(X) is equivalent to (1-X), where X=0 is False and X=1 is True. AND(A, B) is equivalent to (A x B).
What is the mathematical expression for OR(A, B)?
1 - (1 - A)(1 - B), or A + B - AB
Create a code that deletes all lowercase vowels in string X with length N. Use for loop + if statement(s).
EXAMPLE 1: X = "hello world!", N = 12, Y = "hll wrld!"
EXAMPLE 2: X = "no vowels", N = 9, Y = "n vwls"
Y = ""
for i in range(N):
if X[i] not in "aeiou":
Y += X[i]
print(Y)
Given a positive integer N, create a list P of all primes at most N. Use nested for loops, if statement + modulo (%) in your code.
EXAMPLE 1: N = 12, P = [2,3,5,7,11]
EXAMPLE 2: N = 23, P = [2,3,5,7,11,13,17,19,23]
P = []
for i in range(2, N + 1):
is_prime = True
for j in range(2, i):
if i % j == 0:
is_prime = False
if is_prime:
P.append(i)
print(P)