0% found this document useful (0 votes)
69 views17 pages

Phyton

The document discusses the history and features of the Python programming language. Python was created in the late 1980s and is designed to be highly readable. It is interpreted, interactive, object-oriented and supports functional and structured programming. Features include being easy to learn and use, having a large standard library, and being portable.

Uploaded by

blessie balagtas
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)
69 views17 pages

Phyton

The document discusses the history and features of the Python programming language. Python was created in the late 1980s and is designed to be highly readable. It is interpreted, interactive, object-oriented and supports functional and structured programming. Features include being easy to learn and use, having a large standard library, and being portable.

Uploaded by

blessie balagtas
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/ 17

History of Python Easy-to-read − Python code is more clearly

defined and visible to the eyes.


- Python was developed by Guido van
Rossum in the late eighties and early Easy-to-maintain − Python's source code is
nineties at the National Research Institute fairly easy-to-maintain.
for Mathematics and Computer Science A broad standard library − Python's bulk of the
in the Netherlands. library is very portable and cross-platform
compatible on UNIX, Windows, and Macintosh.
Python Interactive Mode − Python has support for an
interactive mode which allows interactive testing
- Python is a high-level, interpreted,
and debugging of snippets of code.
interactive, and object-oriented scripting
language. Python is designed to be highly Portable − Python can run on a wide variety of
readable. It uses English keywords hardware platforms and has the same interface on
frequently whereas other languages use all platforms.
punctuation, and it has fewer syntactical
Extendable − You can add low-level modules to
constructions than other languages.
the Python interpreter. These modules enable
Python is Interpreted − Python is processed at programmers to add to or customize their tools to
runtime by the interpreter. You do not need to be more efficient.
compile your program before executing it. This is
Databases − Python provides interfaces to all
similar to PERL and PHP.
major commercial databases.
Python is Interactive − You can actually sit at a
GUI Programming − Python supports GUI
Python prompt and interact with the interpreter
applications that can be created and ported to
directly to write your programs.
many system calls, libraries and windows
Python is Object-Oriented − Python supports systems, such as Windows MFC, Macintosh, and
the Object-Oriented style or technique of the X Window system of Unix.
programming that encapsulates code within
Scalable − Python provides a better structure and
objects.
support for large programs than shell scripting.
Python is a Beginner's Language − Python is a
great language for beginner-level programmers
and supports the development of a wide range of Benefits
applications from simple text processing to
WWW browsers to games. • It supports functional and structured
programming methods as well as OOP.
• It can be used as a scripting language or
Features of Python can be compiled to byte-code for
building large applications.
Easy-to-learn − Python has few keywords, • It provides very high-level dynamic data
simple structure, and a clearly defined syntax. types and supports dynamic type
This allows the student to pick up the language checking.
quickly. • It supports automatic garbage collection.
• It can be easily integrated with C, C++, o Hexadecimal literals. Example
COM, ActiveX, CORBA, and Java. (0xa1b)
o and much more.
• Literals can be passed to variables or an
identifier

Variables
• (LauchSchool) are used to store
information to be referenced and
manipulated in a computer
program. Think of it as a
container where you can put
some kinds of stuff, and in
programming, those kinds of
Drawbacks
stuff are information or data.
• it's not a speed demon – Python does not • also provide a way of labeling
deliver exceptional performance; data with a descriptive name, so
• in some cases it may be resistant to some our programs can be understood
simpler testing techniques – this may more clearly by the reader and
mean that debugging Python code can be ourselves.
more difficult than with other languages; • as containers that hold
fortunately, making mistakes is also information. Can store data of
harder in Python. different types, and different
types can do different things.
• is a named location reserved to
Literal store values in the memory.
• A variable is created or
• Python Institute (2021) is data whose initialized automatically when
values are determined by the literal itself. you assign a value to it for the
• Ambrose, T. (2019), A literal is an idea first time.
of expressing a non-changing value in a
computer program’s source code. It is Identifier
literally the value itself.
• Unique name of a variable
• Python Institute (2021), Literals can be of
• A legal identifier name must be a non-
almost any type in a programming
empty sequence of characters, must
language, some examples of these types
begin with the underscore(_), or a letter,
are:
and it cannot be a Python keyword. The
o Integer literals. Example (123)
first character may be followed by
o String literals. Example
underscores, letters, and digits.
("Hello")
Identifiers in Python are case-sensitive.
o Boolean literals. Example
(True/False)
Rules to follow when giving name to
a variable:
• the name of the variable must be
composed of upper-case or lower-case
letters, digits, and the character _
(underscore)
• the name of the variable must begin with
a letter;
• the underscore character is a letter; Output
• upper- and lower-case letters are treated
as different (a little differently than in the
real world - Alice and ALICE are the
same first names, but in Python, they are
two different variable names, and
consequently, two different variables);
Variable Scope
• the name of the variable must not be any
of Python's reserved words • According to Marshal (nd.), Scope
refers to the visibility of variables. In
Keywords other words, which parts of your
• or (more precisely) reserved keywords. program can see or use it.
• They are reserved because you mustn't • Normally, every variable has a global
use them as names: neither for your scope. Once defined, every part of your
variables, nor functions nor any other program can access a variable.
named entities you want to create. • in Python, you can declare a variable
locally or globally.

Casting
Local variable
• Specifying the data type of a variable
- the scope of this variable is just visible within a
part of a program, for example, within a
function.

Global variables
• Variables created outside of a function
• Global variables can be used by
Get the Type everyone, both inside of functions and
outside.
• get the data type of a variable with the
type() function.
Function x = memoryview(bytes(5)) memoryview

• Block of codes where it has identifiers


like variable and can only be executed
print() Function
when there is a function call, while Print
is a built-in method to display something • Function name
to the console. • built-in function.
• It prints/outputs a specified message to
the screen/console window.
Built-in datatypes • sends data to the console,

Text Type: str

Numeric Types: int, float, complex


Positional arguments

Sequence Types: list, tuple, range • are the ones whose meaning is dictated
by their position, e.g., the second
Mapping Type: dict argument is outputted after the first, the
Set Types: set, frozenset third is outputted after the second, etc.

Boolean Type: bool
Keyword arguments
Binary Types: bytes, bytearray, memoryview
• are the ones whose meaning is not
dictated by their location, but by a
Example Data Type special word (keyword) used to identify
them.
x = "Hello World" str

x = 20 int
Concatenation Operator
x = 20.5 float
• The + (plus) sign, when applied to two
x = 1j complex strings, becomes a concatenation
x = ["apple", "banana", "cherry"] list operator

x = ("apple", "banana", "cherry") tuple


Replication
x = range(6) range
• The * (asterisk) sign, when applied to a
x = {"name" : "John", "age" : 36} dict
string and number (or a number and
x = {"apple", "banana", "cherry"} set string, as it remains commutative in this
position) becomes a replication operator
x = frozenset({"apple","cherry"}) frozenset
• It replicates the string the same number
x = True bool of times specified by the number.

x = b"Hello" bytes

x = bytearray(5) bytearray
Arithmetic Operator If Statement
• consists of a boolean expression
followed by one or more statements.
• contains a logical expression using
which data is compared and a decision is
made based on the result of the
comparison.
Syntax:
if (condition):
Comparison Operator Statement(s)

Else Statement
• can be combined with an if statement.
• contains the block of code that executes
if the conditional expression in the if
statement resolves to 0 or a FALSE
value.
• else keyword catches anything which
Logical Operator isn't caught by the preceding conditions.
Syntax:
if condition:
True Statements
else:
False statements
Assignment Operator

Elif Statement
• allows you to check multiple
expressions for TRUE and execute a
block of code as soon as one of the
conditions evaluates to TRUE.
• The elif keyword is pythons way of
saying "if the previous conditions were
not true, then try this condition".

Syntax:
if condition:
True Statements
elif condition: more like an iterator method as found in
True Statements other object-orientated programming
else: languages.
False statements • we can execute a set of statements, once
for each item in a list, tuple, set etc.

Single line If Statement


Break Statement
• If you have only one statement to
execute, you can put it on the same line • terminates the current loop and resumes
as the if statement. execution at the next statement, just like
the traditional break found in C.
Syntax:
• most common use for break is when
if condition: expression some external condition is triggered
requiring a hasty exit from a loop
• can be used in both while and for loops.
Single line If....Else Statement
• If you have only one statement to Continue Statement
execute, one for if, and one for else, you
can put it all on the same line: • returns the control to the beginning of
the while loop.
Syntax:
• rejects all the remaining statements in
true_value if condition else false_value the current iteration of the loop and
moves the control back to the top of the
loop.
• can be used in both while and for loops.
While Loop
• repeatedly executes a target statement as
long as a given condition is true. Pass Statement
• we can execute a set of statements as
long as a condition is true • is used when a statement is required
syntactically but you do not want any
Syntax: command or code to execute.
while expression: • is a null operation; nothing happens
when it executes.
statement(s) • also useful in places where your code
will eventually go, but has not been
written yet (e.g., in stubs for example)
For Loop
• used for iterating over a sequence (that
is either a list, a tuple, a dictionary, a set,
Strings
or a string). • We can create them simply by enclosing
• less like the for keyword in other characters in quotes.
programming languages, and works
• are surrounded by either single Concatenation
quotation marks or double quotation
marks. • combining two string values using the
• single quotes and double quotes are '+' symbol.
treated as the same, unlike other Syntax:
programming langue.
• you can assign a multiline string to a str1 = "string value 1" + "string value 2"
variable by using three quotes or three
single quotes
len() function

Accessing String Value • used in determining the length of the


string
• use the square brackets for slicing along
with the index or indices to obtain your capitalize() – changes all string letters to
substring. capitals;

Syntax: join() – joins all items of a tuple/list into one


string;
str[index]
lower() – converts all the string's letters into
• If you want to access the string in lower-case letters;
reverse, you must use a negative index.
The reverse index will start at -1. lstrip() – removes the white characters from the
beginning of the string;
replace() – replaces a given substring with
another;
Escape Character
rstrip() – removes the trailing white spaces from
• the following table is a list of escape or
the end of the string;
non-printable characters that can be
represented with backslash notation. split() – splits the string into a substring using a
• gets interpreted; in single-quoted as well given delimiter;
as double-quoted strings.
strip() – removes the leading and trailing white
spaces;
swapcase() – swaps the letters' cases (lower to
upper and vice versa)
title() – makes the first letter in each word
upper-case;
upper() – converts all the string's letter into
upper-case letters.
• String content can be determined using
the following methods (all of them
return Boolean values):
endswith() – does the string end with a given Dictionaries
substring?
• are unordered, changeable, and indexed.
isalnum() – does the string consist only of letters • have keys and values.
and digits? • Dictionary keys shall be string, but
numbers could also be used.
isalpha() – does the string consist only of letters?
• uses braces ( {} ) to enclose its
islower() – does the string consists only of contents.
lower-case letters?
Sets
isspace() – does the string consists only of white
spaces? • is an unordered collection and does not
record element position or order of
isupper() – does the string consists only of insertion.
upper-case letters? • use braces ( {} ) to enclose its contents.
startswith() – does the string begin with a given
substring?
Functions
Four (4) types of collections in • is a block of program statements that
Python: can be used repetitively in a program.
• is a block of code that performs a
• Lists
specific task when the function is called
• Tuples (invoked).
• Sets • You can use functions to make your
• Dictionaries. code reusable, better organized, and
more readable.
Lists
• can have parameters and return values.
• are just like the arrays declared in other
languages.
• are ordered and indexed. User-Defined Functions
• need not to be homogeneous always
• uses brackets ( [] ) to enclose its • always starts with the keyword def(for
contents. define)
• next after def goes the name of the
function (the rules for naming functions
are exactly the same as for naming
Tuples variables)
• are just like the lists, but tuples are • after the function name, there's a place
immutable. for a pair of parentheses (they contain
• could be heterogeneous nothing here, but that will change soon)
• use parentheses ( () ) to enclose its • the line has to be ended with a colon;
contents.
Syntax: Answer:
def function_name():
num1, num2 = int(input("Enter First Num
#function body ber: ")), int(input("Enter second Numbe
r: "))
print(str(num1) * num2)

Problem No. 2

Map() Function Create a program that will display a rectangle by


allowing the user to input the height.
• Python’s map() is a built-in function that
allows you to process and transform all The first and the last rows shall be displayed as
the items in an iterable without using an +==========+. Ensure that the dashes are
explicit for loop, a technique commonly replicated using string duplication and not typed
known as mapping. as-is.
• is useful when you need to apply a Between the first and last rows, a plus ( + ) sign
transformation function to each item in shall be the first and last characters. Ensure it is
an iterable and transform them into a leveled with the plus signs on the first and last
new iterable. rows.
The first and last rows are included in the count
of the height of the rectangle.
Filter() Function
A minimum of two (2) lines and a maximum of
• Python’s filter() is a built-in function
four (4) lines of codes are allowed in this
that allows you to process an iterable
problem.
and extract those items that satisfy a
given condition. Answer:
• This process is commonly known as a
filtering operation. h = int(input("Enter height: "))-2
• With filter(), you can apply a filtering print("+" + "=" * 10 + "+")
function print(("+" + " " * 10 + "+\n") * h, end
="")
• to an iterable and produce a new print("+" + "=" * 10 + "+")
iterable with the items that satisfy the
condition at hand.
Problem No. 3
Activity 1 Create a program that will allow the user to
Problem No. 1 input two numbers

Create a program that will allow the user to The first number shall be duplicated according
input two numbers. Your code for the input must to the value of the second number.
be on a single line. A third number shall be created by multiplying
Display the first number duplicated according to the value of the second number to 6.
the value of the second number. A maximum of two (2) variables shall be used in
Minimum and maximum of two (2) lines of this problem
codes are allowed in this problem.
Display the sum of all three numbers using f- Your separator characters shall be duplicated
strings. Follow the format of the output below: twice.
The sum of all three numbers are sum., where Use the given code below. You can only modify
sum is the sum of all three numbers. the print() statement.
Answer:
separator = input("Input separator char
acter/s: ")
num1, num2 = int(input("Enter First Num ending = input("Input ending character/
ber: ")), int(input("Enter second Numbe s: ")
r: ")) print("I","love","Python")
num1 = int(str(num1) * num2)
num1 += num2 + num2 * 6
print(f"The sum of all three numbers ar Answer:
e {num1}.")
separator = input("Input separator char
acter/s: ")
Problem No. 4
ending = input("Input ending character/
Create a program that will allow the user to s: ")
print("I","love","Python",sep=separator
input two numbers.
*2,end=ending)
The first number must be an integer, and the
second number must be a float. Ensure that the Activity 2 (Conditional Statement
data types are correct upon inputting.
and Loops)
Display the first number as a float with two
decimal places and the second number as an Problem No. 1
integer. Use the String modulo operator. Follow Create a program that allows the user to input a
the format of the output below: character that will be used in the program and a
First Number: num1, Second Number: num2, number for determining the maximum peak of
where num1 is the first number and num2 is the the triangle.
second number. The input statements must be in a single line,
ensuring one is for a character and the other is
Do the same display using f-strings. Ensure that
the program shall encounter no errors. for a number.

Answer: Upon providing all inputs, create a triangular


display of the character.
num1, num2 = int(input("Enter First Num A maximum of 2 for loops, be it nested or not,
ber: ")), float(input("Enter second Num shall be used. No while loops and conditional
ber: "))
statements shall be used in this program.
print("First Number: %.2f" % num1, "Sec
ond Number: %d" % num2, sep=", ") Answer:
print(f"First Number: {num1:.2f}", f"Se
cond Number: {int(num2)}", sep=", ")
char, num = input("Enter a character: "
), int(input("Enter a number: "))
Problem No. 5 [print(char * i) for i in range(1,num+1
)]
Create a program that will allow the user to [print(char * i) for i in range(num-1,0
input separator and ending characters to a given ,-1)]
print statement
Problem No. 2 Answer:
Create a program that will allow the user to
num = int(input("Enter a number: "))
input a number. ctr = 1
i = 1
After the user input the number, calculate the
while True:
sum of the cubes of the numbers lower than the for a in range(i):
inputted number if ctr > num: break
print(ctr,end="")
Use f-strings to print your final result. ctr+=1
if ctr > num: break
Test your code using the data we provided.
i+=1
Test Data 1: print()

Enter a number: 6 Problem No. 4


The sum of all cubes is 225. Create a program that will allow the user to
Test Data 2 continuously input any number. If the user
inputs zero, then the program will display all
Enter a number: 10 necessary requirements.
The sum of all cubes is 2025. Display the sum of all inputted odd numbers.
Test Data 3: Display the average of all inputted odd numbers
Enter a number: 1 Display the square root of the sum of all inputted
odd numbers. Your result after getting the square
The sum of all cubes is 0.
root must only have 2 decimal places.
Answer:
All displays must use f-strings. You are not
allowed to use any importation in this program.
num,sum = int(input("Enter a number: ")
),0 A maximum of 3 variables is allowed in this
for a in range(1,num): program. No collections shall be used in this
sum += a**3
print(f"The sum of all cubes is {sum}."
program as collections are yet to be discussed
) during this part of the activity.
Answer:
Problem No. 3
Create a program that will display numbers in a ctr=sum=0
while True:
triangular way, while the counting of the num = int(input("Enter a number. 0
numbers is still continuous to exit: "))
if num == 0:
The maximum number shall be determined by break
the user if num%2 != 0:
sum += num
Your triangle should start at 1 number only, then ctr+=1
2 numbers on the next, three numbers on the print(f"The sum of all odd numbers is {
next, and so on, until the maximum number set sum}.")
by the user is reached. print(f"The average of all odd numbers
is {sum/ctr}.")
print(f"The square root of the sum of a
ll odd numbers is {sum**0.5:.2f}.") # ### ### # # ### ### ### ### ### ##
#

Problem No. 5 # # # # # # # # # # # # # #

Create a program that will determine the height # ### ### ### ### ### # ### ### # #
of a pyramid based on the number of blocks # # # # # # # # # # # # #
inputted by the user
# ### ### # ### ### # ### ### ###
The pyramid's layer contains one block more
than the layer above.
Note: the number 8 shows all the LED lights on.
The height of the pyramid is measured by the
Your code has to display any non-negative
number of fully-completed layers. If a layer does
integer number entered by the user.
not have a sufficient number of blocks and
cannot complete the next layer, it is not counted Tip: using a 2-dimensional list containing
in the height of the pyramid. patterns of all ten digits may be very helpful.
Answer:

Limitation:
num = int(input("Enter a number: "))
height = ctr = 1 Only positive numbers are valid as input. If the
while True:
input was invalid, please ask for input again.
num-=ctr
ctr+=1 Answer:
if num >= ctr:
height+=1
continue nums =[
break ["###"," #","###","###","# #","###","#
print(f"The height of the pyramid is {h ##","###","###","###"],
eight}." ["# #"," #"," #"," #","# #","# ","
# "," #","# #","# #"],
["# #"," #","###","###","###","###","#
Activity 3 (Strings) ##"," #","###","###"],
["# #"," #","# "," #"," #"," #","#
Problem No. 1 #"," #","# #"," #"],
["###"," #","###","###"," #","###","#
You've surely seen a seven-segment display. ##"," #","###","###"],
]
It's a device (sometimes electronic, sometimes num = input("Enter a number: ")
mechanical) designed to present one decimal while num.isnumeric() is False:
digit using a subset of seven segments. If you num = input("Invalid Input. Enter a
still don't know what it is, refer to the following number: ")
Wikipedia article (Links to an external site.) for i in range(5):
for x in num:
Your task is to write a program that is able to print(nums[i][int(x)],end=" ")
simulate the work of a seven-display device, print()
although you're going to use single LEDs instead
of segments
Each digit is constructed from 13 LEDs (some
lit, some dark, of course) - that's how we
Problem No. 2
imagine it:
Now, create a program that will simulate Caesar if x in "ABCDEFGHIJKLMNOPQRSTUV
Cipher. WXYZ":
newMessage += chr(ord(x) +
First, ask the user if they want to encrypt or shift if ord(x) + shift < 91 else ord(x
decrypt a message. ) + shift - 26)
continue
Then ask the user what is the number of shifts newMessage += x
they want to use. They may only select from 1 to else: # Decipher
for x in message:
25 since 26 will just revert the original shifting
if x in "ABCDEFGHIJKLMNOPQRSTUV
of the alphabet. WXYZ":
newMessage += chr(ord(x) -
Then ask the message to be encrypted/decrypted.
shift if ord(x) - shift > 64 else ord(x
Depending on the first input by the user whether ) - shift + 26)
continue
to encrypt or decrypt the message, perform the
newMessage += x
shifting on the letters from the input message print(f"Output: {newMessage}")
and display the output in all capital letters.
Limitation: Problem No. 3

Only Alphabet Letters will be Do you know what a palindrome is


encrypted/decrypted in the message
It's a word that looks the same when read
(ABCDEFGHIJKLMNOPQRSTUVWXYZ). If
forward and backward. For example, "kayak" is
there are any numbers or special characters on
a palindrome, while "loyal" is not.
the message, leave it as it is.
Your task is to write a program which:
Only integer 0 and 1 are valid as the first input.
If the input was invalid, please ask for input asks the user for some text;
again.
checks whether the entered text is a palindrome,
Only integers from 1 to 25 are valid as the and print the result.
second input. If the input was invalid, please ask
for input again. Note:

Answer: assume that an empty string isn't a palindrome;


treat upper- and lower-case letters as equal;
choice = int(input("Please select [0] C
ipher / [1] Decipher: ")) spaces are not taken into account during the
while choice not in [0,1]: check - treat them as non-existent;
choice = int(input("Invalid option.
Please select [0] Cipher / [1] Decipher there are more than a few correct solutions - try
: ")) to find more than one.
shift = int(input("Enter the numbe rof
shift (1-25): ")) Answer:
while shift not in [a for a in range(1,
26)]: s = input("Enter a word, a phrase, or a
shift = int(input("Invalid shift. E sentence: ").lower().replace(" ","")
nter the numbe rof shift (1-25): ")) print("It is not a palindrome." if s !=
message = input("Enter the message: "). s[::-1] or s == '' else "It is a palind
upper() rome.")
newMessage = ""
if choice == 0: # Cipher
for x in message: Problem No. 4
Your task is to write a program which: digit = 10
while digit > 9:
asks the user for two separate texts; digit = 0
for d in birthday:
checks whether the entered texts are anagrams digit += int(d)
and prints the result. birthday = str(digit)
print(f"Digit of life is: {digit}")
Note:
assume that two empty strings are not anagrams; Quiz 1
treat upper- and lower-case letters as equal; • The most important difference between
spaces are not taken into account during the integer and floating-point numbers lies
check - treat them as non-existent in the fact that:
o they are stored differently in the
Tips: computer memory
• The ** operator:
You can use sort methods.
o performs exponentiation
Answer: • A value returned by the input() function
is of what data type?
s1,s2 = input("Enter first string: ").l o String
ower().replace(" ",""),input("Enter sec • Only one of the following statements is
ond string: ").lower().replace(" ","") true - which one?
print("Not Anagrams" if sorted(s1) != s
o addition precedes
orted(s2) or (s1 == '' or s2 == '') els
e "Anagrams") multiplication
o neither statements can be
evaluated
Problem No. 5
o multiplication precedes
Your task is to write a program which: addition
• The meaning of the positional parameter
asks the user her/his birthday (in the format
is determined by its _______n.
YYYYMMDD, or YYYYDDMM, or o Position
MMDDYYYY - actually, the order of the digits
• The result of the following addition:
doesn't matter)
• 123 + 0.0
outputs the Digit of Life for the date. o 123.0
• Right-sided binding means that the
Limitations: following expression
Only positive numbers are valid input. If the • 1 ** 2 ** 3 will be evaluated:
input is invalid, ask for input again. o from right to left
• The escape character owes its name to
The valid number of input must be 8 digits. If the fact that it:
the input is invalid, ask for input again. o changes the meaning of the
Answer: character next to it
• A keyword is a word that:
birthday = input("Enter birthday: ") o cannot be used as a variable
while not birthday.isnumeric() or len(b name
irthday) != 8: • The // operator:
birthday = input("Invalid input. En o performs integer division
ter birthday: ")
• What is the output of the following Quiz 2 (Conditional Statement and
snippet?
Loops)
• _____ loop can execute a set of
o The value is 2.200000. statements, once for each item in a
• What is the output of the following collection.
snippet? o For
• The _____ statement terminates the
current loop and resumes execution at
the next statement.
o Break
• A _____ loop statement repeatedly
executes a target statement as long as
the given condition is true.
o While
o Hi Gabriel. You are a
• A/An _____ operator is an operator used
programmer.
to assign a new value to a variable,
• What is the output of the following
property, event, or indexer element.
snippet?
o Assignment
• Python language has while, for, and do
while as its fundamental loop
o JonathanJonathanJonathanJorda statements.
nJordanJordanJordanprogramm o False
er • The _____ function returns a sequence
• What is the output of the following of numbers, starting from 0 by default,
snippet? and increments by 1 (by default), and
stops before a specified number.
o Range
o Error • The syntax for the range() function is:
• What is the output of the following • range(start_value, stop_value, _____
snippet? o step
• The _____ operator performs the basic
mathematical operations.
o Arithmetic
• _____ operators are used to test if a
o Error
sequence is presented in an object.
o Membership
• The syntax for the short-hand if...else
statement is:
• true_value if condition _____
false_value
o else
• What is the output of the following
snippet?
o 0 1 4 9 16 25 36 49 64 81 • Add all items of dictionaries d1 and d2
• What is the output of the following to a new dictionary d3.
snippet?

o d3.update(item)

• Complete the code by supplying the


o 15110
correct statement to replace the
• What is the output of the following
comment.
snippet if the inputted value is equal to
• Convert the two-dimensional tuple into
50?
a dictionary and store in colDict
variable. Provide necessary spaces for
the assignment.

o colDict = dict(colors)

• What is the output of the following


snippet?
o 18 12

Quiz 3 (Collections)
o 666666
• What is the output of the following
snippet?

o Error

• Complete the code by supplying the


correct statement to replace the
comment.
• Find the number of duplicates of number
2.

o var.count(2)
• Complete the code by supplying the
correct statement to replace the
comment.

You might also like