Name: Student Name
Input, processing, storage, output
The physical parts of a computer
Programs that run on hardware
Binary
A named container for a value
A text-based interface for entering commands; a.k.a. console or CLI
Central Processing Unit
Integer, floating point number, string, boolean, none type
Boolean
input() return?String
2 + 2'hi' * 3'foo' + 'bar'5 - 4C 'foo' + 'bar'
= and ==?= assigns a value while == compares a value
user_prompt = "Enter a number between 1 and 10: "
user_input = input( user_prompt )
user_number = int( user_input )
# TODO
Write an if statement that prints “You picked the middle number!” if user_number equals 5.
if user_number == 5:
print( "You picked the middle number!" )
else statement exist without an if?No
x = int( input() )
if x == 5
print( "x is 5" )
Missing :
x = int( input() )
if x == 5:
print( "x is 5" )
Invalid indentation
/ always return?Divides, and always produces a floating-point number
// operator do?Floor division. It drops the remainder and produces an integer
% operator do?Modulus. It gives the remainder
*= operator do?Multiplies, then assigns the result
age >= 18 produce?A Boolean: True or False
and, or, and not
print(not True)
False
rylan_is_old = False
rylan_is_teacher = True
if rylan_is_old and rylan_is_teacher:
print( "Rylan is a wise old sage" )
elif rylan_is_teacher:
print( "Rylan is worth listening to" )
else:
print( "Rylan is just a guy" )
Rylan is worth listening to
Semantics is the meaning. Syntax is the words, characters, and grammar
A reusable section of code
A name in a function definition for a value the caller passes in
def compute_sum( x, y ):
return x + y
print( "Enter two numbers to be summed:" )
x = int( input() )
y = int( input() )
# TODO
Compute the sum using the defined function and print the result.
print( compute_sum(x, y) )
# TODO
x = int( input() )
x_squared = compute_square( x )
print( x, "squared is", x_squared )
Define the missing function.
def compute_square(x):
return x * x
def get_word( word_type ):
prompt = f"Enter a word that is a { word_type }: "
return input( prompt )
# TODO
print( f"Once upon a time there was a { noun }." )
print( f"The { noun } was very { adjective }." )
print( f"One day the { noun } decided to { verb } at the { location }!" )
print( "That was a weird day." )
print( "THE END" )
Add the required function calls and assignments.
noun = get_word( "noun" ) adjective = get_word( "adjective" ) verb = get_word( "verb" ) location = get_word( "location" )