CompSci II Final

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

1/19

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.

20 Terms

1
New cards

1. What is a correct command line syntax for checking if python is installed on your computer?

(and to check the Python version also)

python --version

python ##version

python version

python --version

2
New cards

2. What is a correct syntax to exit the Python command line interface?

exit()

stop()

end()

exit()

3
New cards

3. True or False: Indentation in Python is for readability only.

True

False

False

4
New cards

4. What is the missing part of the code below to output “Hello World”? ________("Hello World")

run

output

print

print

5
New cards

5. Complete the code block, print "YES" if 5 is larger than 2.

if 5 > 2:

print “YES”

print("YES")

print (YES)

print("YES")

6
New cards

6. What is a correct way to declare a Python variable?

var x = 5

#x = 5

$x = 5

x = 5

x = 5

7
New cards

7. True or False: You can declare string variables with single or double quotes. Example:

x = "John"

# is the same as

x = 'John'

True

False

True

8
New cards

8. True or False: Variable names are not case-sensitive. Example:

a = 5

# is the same as

A = 5

True

False

False

9
New cards

9. What is a correct syntax to add the value 'Hello World', to 3 variables in one statement?

x, y, z = 'Hello World'

x = y = z = 'Hello World'

x|y|z = 'Hello World'

x = y = z = 'Hello World'

10
New cards

10. Consider the following code:

print('Hello', 'World')

What will be the printed result?

Hello, World

Hello World

HelloWorld

Hello World

11
New cards

11. Consider the following code:

a = 'Hello'

b = 'World'

print(a + b)

What will be the printed result?

a + b

Hello World

HelloWorld

HelloWorld

12
New cards

12. Consider the following code:

a = 4

b = 5

print(a + b)

What will be the printed result?

45

9

4 + 5

9

13
New cards

13. Consider the following code:
x = 'awesome'
def myfunc():
x = 'fantastic'
myfunc()
print('Python is ' + x)
What will be the printed result?

Python is awesome
Python is fantastic

Python is awesome

14
New cards

14. Which is NOT a legal numeric data type in Python:


int
long
float

long

15
New cards

15. What will be the result of the following code:
x = 'Welcome'
print(x[3])


Wel
c
Welcome Welcome Welcome

c

16
New cards

16. Use the len function to print the length of the string.
x = "Hello World"


print(len(x))
print(lenx)
print(len x)

print(len(x))

17
New cards

17. Get the first character of the string txt.
txt = "Hello World"


x = 0
x = txt[0]
x = text(0)

x = txt[0]

18
New cards

18. Select the correct keyword to check if the word 'free' is present in the text:
txt = 'The best things in life are free!'
if 'free' __________ txt:
print('Yes, free is present in the text.')


contains
present
in
match

in

19
New cards

19. What is a correct syntax to print a string in upper case letters?


'Welcome'.upper()
'Welcome'.toUpper()
'Welcome'.toUpperCase()

'Welcome'.upper()

20
New cards

20. Return the string without any whitespace at the beginning or the end.


txt = " Hello World "
x = txt.strip()
x = txt.strip
x = txt.strip(0)

x = txt.strip()