python test

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/30

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

31 Terms

1
New cards

What function is used to display output in Python?

print()

2
New cards

How do you write a single-line comment in Python?

Using the # symbol at the beginning of the line

3
New cards

What is special about Python's syntax regarding code blocks?

Python uses indentation (typically 4 spaces) instead of braces to define code blocks

4
New cards

How do you create a variable in Python?

Use the assignment operator = (e.g., x = 5)

5
New cards

What are the four common data types in Python?

int (integer), float (decimal), str (string), bool (boolean)

6
New cards

What function collects user input from the keyboard?

input()

7
New cards

How do you convert user input from a string to an integer?

Use int() (e.g., int(input("Enter a number: ")))

8
New cards

What operator performs integer (floor) division?

//

9
New cards

What operator gives the remainder of division?

% (modulo operator)

10
New cards

What operator raises a number to a power?

** (exponentiation operator)

11
New cards

What comparison operator checks for equality?

==

12
New cards

What comparison operator checks for inequality?

!=

13
New cards

What are the three main conditional statements?

if, elif, and else

14
New cards

What keyword starts a conditional statement that checks an alternative condition?

elif (else if)

15
New cards

How do you create a for loop that runs 5 times?

for i in range(5):

16
New cards

What function generates a sequence of numbers for iteration?

range()

17
New cards

What type of loop continues while a condition is True?

while loop

18
New cards

How do you create a list containing the numbers 1, 2, and 3?

my_list = [1, 2, 3]

19
New cards

How do you access the first element of a list?

Use index [0] (e.g., my_list[0])

20
New cards

What function returns the number of items in a list?

len() (e.g., len(my_list))

21
New cards

What data type would you use to store a person's name?

str (string)

22
New cards

What data type would you use to store whether a user is logged in?

bool (boolean: True or False)

23
New cards

What is a recommended practice for naming variables?

Use meaningful, descriptive names (e.g., user_age instead of ua)

24
New cards

How do you convert a string to a floating-point number?

Use float() (e.g., float("3.14"))

25
New cards

What comparison operators check "greater than" and "greater than or equal to"?

> and >=

26
New cards

What comparison operators check "less than" and "less than or equal to"?

< and <=

27
New cards

What is the term for expressions that evaluate to True or False?

Boolean expressions

28
New cards

How can you control the flow within loops?

Using break (exit loop) and continue (skip to next iteration)

29
New cards

Write code that asks for the user's age and prints it

age = input("Enter your age: ") print("Your age is:", age)

30
New cards

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")

31
New cards

Write code that creates a list of fruits and prints each one

fruits = ["apple", "banana", "cherry"] for fruit in fruits: print(fruit)