Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
4 views5 pages

Python Exam 2 Bat

This document presents a Python exam composed of multiple-choice questions and practical exercises. The exam contains 18 multiple-choice questions on basic Python concepts such as operators, strings, lists, loops, and functions. It also includes 3 practical exercises to debug code and develop programs that count vowels and consonants in words.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views5 pages

Python Exam 2 Bat

This document presents a Python exam composed of multiple-choice questions and practical exercises. The exam contains 18 multiple-choice questions on basic Python concepts such as operators, strings, lists, loops, and functions. It also includes 3 practical exercises to debug code and develop programs that count vowels and consonants in words.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

IES Sorolla

- --------------------------------------------------------------------------------------------
Name and Surname ………………………………………
Course: ………………………………………
- --------------------------------------------------------------------------------------------

Python Exam

Test
Multiple choice questions penalize ⅓ of the value of the questions.

What would the following program print?


>>> resto = 7 % 3
>>> print restaurant

7
b) 3
c) 1
d) 2

2. Which of the following statements indicates a comment in Python?


a) /* This is a comment */
// This is a comment
c) # This is a comment
d) – This is a comment –
e)
3. Which of the following are reserved words?
a) var
b) in
c) list
d) for
e) print

4. What would be the result of executing the following code?


2.50
2.00
b) 2.5
c) 2.50
d) 2

5. What would be the result of executing the following code?


5 is greater than 8

a) True
b) False
c) 5
d) 8

6. What value should x have for the program to print 'option c'?
x = ?
if x < 5:
option a
elif x == 5:
option b
else
print 'option c'

a) 5
b) 4
9
-1

1/5
IES Sorolla

7. What would be the result of evaluating the following statement?


6 is greater than or equal to 2 and (6 divided by 2) is greater than 2

a) True
b) False

8. What would be the result of executing the following statement?


Hello world

'H'
'u'
c) It would generate an error

9. What would be the result of executing the following statement?


6
6
b) 7
c) 5
d) 1

10. What reserved word is used in Python to create a new function?


a) def
b) function
c) return
d) max

11. What will the following Python program display on screen?


Python exam
resultado
i = len(sentence) - 1
while i >= 0:
result = result + sentence[i]
i = i - 2

Python exam
Exam phenot
'nhy eaE'
It would generate an error

12. What would be the result of executing the following statement?


Python exam
a) It would generate an error
b) x
c) a
d) python

13. What would be the result of executing the following statement?


Monty Python
>>> print s[4:]

and Python
Python
Python
d) It would generate an error

2/5
IES Sorolla

14. What would be the result of executing the following statement?


word = 'banana'
>>> word.find('na')

a) 0
b) 2
c) 4
d) 6

15. What would be the result of executing the following statements?


a = ['student1', 'student2', 'student3']
>>> b = a
a[1] = 'student10'
>>> print b

a) ['alumno1','alumno2','alumno3']
b) ['alumno10','alumno2','alumno3']
c) ['alumno1','alumno10','alumno3']
d) ['alumno1','alumno2','alumno10']

16.Write the statement to create an empty dictionary. Its name must be


ex_dict.

17. Given the following list, very_list = ["you", "coffee", "sugar", "saccharin"]. Write the
Python statement that prints the value 'sugar' to the console

3/5
Sorolla High School

18.After executing the following code, what is the final value of the variable a?
>>> vowels = ['a','e','i','o','u']
python is cool
>>> i = 0
>>> a = 0
>>> while (i < len(text)):
>>> if (text[i] not in vowels):
>>> a = a + 3
>>> else:
>>> a = a + 1
>>> i = i + 1

Solve the exercise by tracing it, that is, show the value of the variables.
indicated in the table for each iteration of the while loop

i text[i] a

4/5
IES Sorolla

1. Practice
The following code in python draws a square of the dimensions and the pattern
indicated, but it has some errors in the lexicon and grammar, not semantic, it is
to say that it is not necessary to add or modify any instructions for it to do so
that you have to do. You will find the code at the following URL:
Invalid input. Please provide text for translation.
Correct and run the code in your usual development environment, once resolved.
the errors, save the file as ex1.pyy and send it to the indicated task.

Example of correct execution

In [7]: run ex1.py


########
Square
########

rows?6
columns?3
pattern?

^^^
^^^
^^^
^^^
^^^
^^^

2. Implement the code of a program that, upon entering a word, indicates the
number of vowels and consonants it has
Hint: use the 'in' operator to check if a letter is a vowel or not; e.g.:
if letter in "aeiou":
Example
Count vowels and consonants
>>> ===================
baccalaureate
The word 'bachillerato' contains 7 consonants and 5 vowels.

Save the file as ex2.pyy and send it to the indicated task.

3. Based on the solution of the previous exercise, modify the program so that
Once a word is introduced, indicate the number of different vowels and consonants.
Example
Count different vowels and consonants
>>> =========================
anguish
The word bachillerato contains 3 consonants and 2 vowels.

Save the file as ex3.pyy and send it to the indicated task.

5/5

You might also like