CS: Operators in Python Flashcards
What are operands?
They are the values or variables manipulated by operators (in mathematical or programming operations. ex: 3, 5)
What are operators?
Operators are symbols or keywords in programming and mathematics that perform specific actions on operands (ex: +, -, ==.)
What is modulus?
It’s the remainder that’s left after dividing 2 numbers. For example, 3%2=1.
What does this operator symbolize? **
Exponent, or power.
Write a program that asks a user to enter two numbers, multiplies and subtracts them, and then prints the answer for each.
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)
Write a program to determine and display the average of 3 user-given numbers.
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)
What’s the output?
a = 5
b = a
print (“Output =”, b)
5
What does a+=b mean?
a=a+b
What does a-=b mean?
a=a-b
What does a*=b mean?
a=a*b
What’s the output?
a = 5
b = 3
a -= b
print(“Output = “, a)
2
What’s the output?
a = 15
b = 4
a *= b
print “Output =”, a)
60
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)
6
2
8
2.0
16
1
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)
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
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)
Value of a is:
20
Value of b is: 4.0
Value of c is:
5