Computer Science I: Midterm

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/24

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.

25 Terms

1
New cards

1. What is the correct way to comment a single line in Python?

# This is a comment

// This is a comment

/* This is a comment */

<!-- This is a comment -->

# This is a comment

2
New cards

2. Which Python function is used to get the length of a list?

len()

count()

size()

length()

len()
3
New cards

3. What is a correct syntax to output "Hello World" in Python?

echo("Hello World")

echo "Hello World"

print("Hello World")

p("Hello World")

print("Hello World")

4
New cards

4. Which one is NOT a legal variable name?

my_var

Myvar

_myvar

my-var

my-var
5
New cards

5. How do you create a variable with the numeric value 5?

x = int(5)

x = 5

Both the other answers are correct

x = int(5)

x = 5

6
New cards

6. What is the correct file extension for Python files?

.pt

.pyth

.py

.pyt

.py
7
New cards

7. How do you create a variable with the floating number 2.8?

Both the other answers are correct

x = 2.8

x = float(2.8)

x = 2.8

x = float(2.8)

8
New cards

8. What is the correct syntax to output the type of a variable or object in Python?

print(typeOf(x))

print(typeof(x))

print(type(x))

print(typeof x)

print(type(x))
9
New cards

9. In Python, 'Hello', is the same as "Hello"

False

True

True
10
New cards

10. What is a correct syntax to return the first character in a string?

x = sub("Hello", 0, 1)

x = "Hello".sub(0, 1)

x = "Hello"[0]

Note: In the code x = "Hello"[0], "Hello" is a string, and [0] is used to access the first character of that string, which is "H". So, x will be assigned the value "H".

x = "Hello"[0]
11
New cards

11. Which method can be used to remove any whitespace from both the beginning and the end of a string?

trim()

len()

ptrim()

strip()

strip()
12
New cards

12. Which method can be used to return a string in upper case letters?

toUpperCase()

upper()

uppercase()

upperCase()

upper()
13
New cards

13. Which method can be used to replace parts of a string?

replaceString()

repl()

replace()

switch()

replace()
14
New cards

14. Which operator is used to multiply numbers?

*

#

%

X

*
15
New cards

15. Which operator can be used to compare two values?

><

==

<>

=

==

16
New cards

16. Which of these collections defines a LIST?

["apple", "banana", "cherry"]

("apple", "banana", "cherry")

{"apple", "banana", "cherry"}

{"name": "apple", "color": "green"}

["apple", "banana", "cherry"]
17
New cards

17. Which of these collections defines a TUPLE?

("apple", "banana", "cherry")

{"apple", "banana", "cherry"}

["apple", "banana", "cherry"]

{"name": "apple", "color": "green"}

("apple", "banana", "cherry")
18
New cards

18. Which of these collections defines a SET?

{"apple", "banana", "cherry"}

["apple", "banana", "cherry"]

("apple", "banana", "cherry")

{"name": "apple", "color": "green"}

{"apple", "banana", "cherry"}
19
New cards

19. Which of these collections defines a DICTIONARY?

{"name": "apple", "color": "green"}

["apple", "banana", "cherry"]

("apple", "banana", "cherry")

{"apple", "banana", "cherry"}

{"name": "apple", "color": "green"}

20
New cards

20. Which collection is ordered, changeable, and allows duplicate members?

SET

LIST

TUPLE

DICTIONARY

LIST

21
New cards

21. Which collection does not allow duplicate members?

TUPLE

SET

LIST

SET

22
New cards

22. How do you start writing an if statement in Python?

if x > y then:

if (x > y)

if x > y:

if x > y:
23
New cards

23. How do you start writing a while loop in Python?

x > y while {

while (x > y)

while x > y:

while x > y {

while x > y:
24
New cards

24. How do you start writing a for loop in Python?

for x > y:

for each x in y:

for x in y:

for x in y:
25
New cards

25. Which statement is used to stop a loop?

Break

Return

Exit

stop

Break