CS: Operators in Python Flashcards

1
Q

What are operands?

A

They are the values or variables manipulated by operators (in mathematical or programming operations. ex: 3, 5)

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

What are operators?

A

Operators are symbols or keywords in programming and mathematics that perform specific actions on operands (ex: +, -, ==.)

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

What is modulus?

A

It’s the remainder that’s left after dividing 2 numbers. For example, 3%2=1.

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

What does this operator symbolize? **

A

Exponent, or power.

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

Write a program that asks a user to enter two numbers, multiplies and subtracts them, and then prints the answer for each.

A

num1 = float(input(“Enter your first number: “))
num2 = float(input(“Enter your second number: “))
result1 = num1 * num2
print(“Result of multiplication:”, result1)
result2 = num1 - num2
print(“Result of subtraction:”, result2)

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

Write a program to determine and display the average of 3 user-given numbers.

A

num1 = float(input(“Enter the first number: “))
num2 = float(input(“Enter the second number: “))
num3 = float(input(“Enter the third number: “))
average = (num1 + num2 + num3) / 3
print(“The average of”, num1, “,”, num2, “, and”, num3, “is:”, average)

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

What’s the output?
a = 5
b = a
print (“Output =”, b)

A

5

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

What does a+=b mean?

A

a=a+b

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

What does a-=b mean?

A

a=a-b

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

What does a*=b mean?

A

a=a*b

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

What’s the output?
a = 5
b = 3
a -= b
print(“Output = “, a)

A

2

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

What’s the output?
a = 15
b = 4
a *= b
print “Output =”, a)

A

60

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

What’s the output?
a = 4
b = 2
a += b
print(a)
a = 4
a -= 2
print(a)
a = 4
a *= 2
print(a)
a = 4
a /= 2
print(a)
a = 4
a **=2
print(a)
a = 5
a %= 2
print(a)

A

6
2
8
2.0
16
1

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

What’s the output?
a = 21
b = 10
c = 0
c = a + b
print (“Line 1 - Value of c is “, c)
c += a
print (“Line 2 - Value of c is “, c)
c *= a
print (“Line 3 - Value of c is “, c)
c /= a
print (“Line 4 - Value of c is “, c)

A

Line 1 - Value of c is 31
Line 2 - Value of c is 52
Line 3 - Value of c is 1092
Line 4 - Value of c is 52.0

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

What’s the output?
a = 10
b=20
c=25
a *=2
b /= 5
c %= 10
print (“Value of a is: “, a)
print (“Value of b is: “ b)
print (“Value of c is: “, c)

A

Value of a is:
20
Value of b is: 4.0
Value of c is:
5

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

What’s the output?
a = 10
a += 10
print (“Result of line 1 is “, a )
a = 10
a *= a
print (“Result of line 2 is “, a)
a = 10
a /= a
print (“Result of line 3 is “, a)
a = 10
a %= a
print (“Result of line 4 is “, a)
a = 10
a **= a
print (“Result of line 5 is “, a)

A

Result of line 1 is 20
Result of line 2 is 100
Result of line 3 is 1.0
Result of line 4 is 0
Result of line 5 is 10000000000

17
Q

What’s the output?
a = 10
a += 10
print (“Result of line 1 is “, a )
a *= a
print (“Result of line 2 is “, a )
a /= a
print (“Result of line 3 is “, a )
a %= a
print (“Result of line 4 is “, a)
a **= a
print (“Result of line 5 is “, a)

A

Result of line 1 is 20
Result of line 2 is 400
Result of line 3 is 1.0
Result of line 4 is 0.0
Result of line 5 is 1.0