some characters
sign-up QR Code
print
functionprint
functionprint()
sends characters (strings) to the standard outputString concatenation:
In your groups, try the following operations:
"abc" * 4
+
and ,
. What is the difference?They sang AaAaAaAaAaAaAaAaAaAa
solution 1:
solution 2:
solution 3:
print
statementsprint
statementsprint
function moves the cursor to the next line after printing, unless you specify otherwise.Are You In College?
What other characters can you use for values for the end
parameter?
Write a simple program that prints the following output to the python console:
He said, "What's up?" Joe's friend didn't reply.
double quotes:
He said, "What's up?"
Joe's friend didn't reply.
single quotes:
Variable assignment does not produce any output to the console. Run the following code:
How would we print these variables?
Without variables:
With variables:
"hello"
or 'hello'
3
3.14
True
or False
Use the function type()
with each literal type.
+
: plus
-
: minus
*
: multiple
/
: divide
**
: power
//
: divide and floor
%
: modulos
What value will each of these variables take on? No computers!
a1 = 5 / 5 * 10 * 5 a2 = 5 / (5 * 10) * 5 b1 = 5 * 10 - 2 b2 = 5 * (10 - 2) c = (3 // (4 // 5)) + 1
a1 = 5 / 5 * 10 * 5
a2 = 5 / (5 * 10) * 5
b1 = 5 * 10 - 2
b2 = 5 * (10 - 2)
# c = (3 // (4 // 5)) + 1 ERROR -- Zero Division
print(a1)
print(a2)
print(b1)
print(b2)
50.0
0.5
48
40
Note that the division operator returns a float even when both numerator and denominator are integers
round()
round()
Use the round() function to get a floating-point number rounded to the specified number of decimals.
Syntax:
The number of digits (ndigits
) is optional, but we will often round number to two decimals:
round()
Use the round() function to get a floating-point number rounded to the specified number of decimals.
Syntax:
Rounding is done toward the nearest even choice:
Variable assignments are not like math — they can appear in equations that make no mathematical sense.
x = x + 2
means “take the current value of x, add it with 2, and assign the resulting value (7) to x as its new value.”
Write code to calculate the area of a circle when radius is 3:
You have 5 minutes to complete the quiz.
Comments
Comments are text that is meant to be read, but not executed. The purpose is to improve readability.