Review of the first two weeks
CS 149, 02-Sep-2024
print()
Documentation:
Examples:
>>> print("Hello!") Hello! >>> print(1, 2, 3, sep=" + ") 1 + 2 + 3 >>> print("Same ", end="") print("line!") Same line!
input()
>>> input() 123 '123' >>> input("Your name? ") Your name? Dr. Mayfield 'Dr. Mayfield'
int()
float()
str()
>>> int("149") 149 >>> float("1.49") 1.49 >>> str(149) '149'
_
prefix = "CS" number = 149 univ_name = "JMU"
+
-
*
**
/
//
%
>>> 1 - 2**3 -7 >>> 21 // 5 4 >>> 21 % 5 1 >>> "Ho"*3 + "!" 'HoHoHo!'
'
"
\n
\t
\\
f"{...}"
>>> print('She said, "Hello!"\nI was shocked!') She said, "Hello!" I was shocked! >>> f"{3.14159:.3f}" '3.142'
See https://w3.cs.jmu.edu/mayfiecs/cs149/
course = input("Enter the course: ") semester = input("Enter the semester: ") print(f"Welcome to {course}, {semester}!")
{}
:.3f
math
import math
>>> math.pi 3.141592653589793 >>> math.floor(math.pi) 3 >>> math.ceil(math.pi) 4