How do you print the statement: Hello World
print(Hello World)
Create a variable x and set it to the string: "test"
x = "test"
What is an example of a string?
"hi"
Cast the integer: 42 to a string
str(42)
What 2 values can a boolean return?
True, False
x = input("enter x: ")
print the sum of 3 and 5
print(3+5)
What is an example of an integer?
21
Put together separate strings "Hello " and "World" to make one message.
message = "Hello " + "World
Write an if statement comparing 2 and 3.
if 2 == 3:
How do you create a function?
set variables to 9 and 4 and find the difference
num1 = 9
num2 = 4
difference = num1 - num2
What is the difference between an integer and a float?
Integer must be whole. Float can include decimals.
Turn the integer "36" into a string.
str("36")
What does an else statement do?
The else statement is executed in the case that the if condition is false.
Create a function that gets the user's name and prints it back to them.
function():
name = input("what is your name?")
print(name)
what does the operator: // mean?
Floor Division, returns the largest possible integer
Give an example of a boolean.
number1 == number2
Get the user's name and return: hi user_name
print("hi " + input("what's your name? "))
What are Python's 3 default Boolean Operators?
and (only returns true for Boolean if both are true)
or (returns true for Boolean if either of the arguments are true)
not (inverts modifying argument)
function():
number1 = input("enter first number: ")
number2 = input("enter second number: ")
print(int(number1) + int(number2))
Create 3 integer variables and find the mean of them.
x = 1
y = 2
z = 3
mean = float(x + y + z) / float(3)
sum = input() + 8
input() returns a string, which cannot be added with an integer. You must first cast it using int().
Get the user's age and return: you will be - in 4 years.
print("you will be " + str(int(input("age: ")) + 4) + " in 4 years")
Ask the user for a number, if it is equal to 7, then return correct, but if not, return incorrect.
number = input("number: ")
if number == 7:
print("correct")
else:
print("incorrect")