1/30
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
What function is used to display output in Python?
print()
How do you write a single-line comment in Python?
Using the # symbol at the beginning of the line
What is special about Python's syntax regarding code blocks?
Python uses indentation (typically 4 spaces) instead of braces to define code blocks
How do you create a variable in Python?
Use the assignment operator = (e.g., x = 5)
What are the four common data types in Python?
int (integer), float (decimal), str (string), bool (boolean)
What function collects user input from the keyboard?
input()
How do you convert user input from a string to an integer?
Use int() (e.g., int(input("Enter a number: ")))
What operator performs integer (floor) division?
//
What operator gives the remainder of division?
% (modulo operator)
What operator raises a number to a power?
** (exponentiation operator)
What comparison operator checks for equality?
==
What comparison operator checks for inequality?
!=
What are the three main conditional statements?
if, elif, and else
What keyword starts a conditional statement that checks an alternative condition?
elif (else if)
How do you create a for loop that runs 5 times?
for i in range(5):
What function generates a sequence of numbers for iteration?
range()
What type of loop continues while a condition is True?
while loop
How do you create a list containing the numbers 1, 2, and 3?
my_list = [1, 2, 3]
How do you access the first element of a list?
Use index [0] (e.g., my_list[0])
What function returns the number of items in a list?
len() (e.g., len(my_list))
What data type would you use to store a person's name?
str (string)
What data type would you use to store whether a user is logged in?
bool (boolean: True or False)
What is a recommended practice for naming variables?
Use meaningful, descriptive names (e.g., user_age instead of ua)
How do you convert a string to a floating-point number?
Use float() (e.g., float("3.14"))
What comparison operators check "greater than" and "greater than or equal to"?
> and >=
What comparison operators check "less than" and "less than or equal to"?
< and <=
What is the term for expressions that evaluate to True or False?
Boolean expressions
How can you control the flow within loops?
Using break (exit loop) and continue (skip to next iteration)
Write code that asks for the user's age and prints it
age = input("Enter your age: ") print("Your age is:", age)
Write code that checks if a number is positive, negative, or zero
if num > 0: print("Positive") elif num < 0: print("Negative") else: print("Zero")
Write code that creates a list of fruits and prints each one
fruits = ["apple", "banana", "cherry"] for fruit in fruits: print(fruit)