2020 Aiep HS S10 SC

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Asian MathSci League, Inc (AMSLI)

Website: amsliphil.com
Email address: amsliphil@yahoo.com

Student Copy
High School Session 10

Lab Activity 3: Review

Exercise 1 Goal: Convert “firstname lastname” to “lastname, firstname”

names = ["Isaac Newton", "Albert Einstein", "Niels Bohr", "Marie Curie", "Charles Darwin", "Louis Pasteur", "Galileo
Galilei", "Margaret Mead"]

using: a) loop, b) list comprehension

Exercise 2. Goal: Write down the cubes of the first 10 natural numbers
Produce: [0, 1, 8, 27, 64, 125, 216, 343, 512, 729]
Using: a) loop, b) list comprehension

Exercise 3. Goal: Given an input list nums, produce a list of the even numbers in nums

nums = [3, 1, 4, 1, 5, 9, 2, 6, 5]

Exercise 4. Goal: Return all ordered pairs of 2 die-rolls that give a sum greater than or equal to eight.
Result list should be a list of 2-tuples: [(2, 6), (3, 5), (3, 6), (4, 4), (4, 5), (4, 6), (5, 3), (5, 4), (5, 5), (5, 6), (6, 2), (6, 3),
(6, 4), (6, 5), (6, 6)]

Exercise 5. Goal: Concatenate two lists index-wise


Example:

Exercise 6. Concatenate two lists in the following order:

Exercise 7. Given two lists. Iterate both lists simultaneously such that list1 should display item in original order and
list2 in reverse order.

Prepared by John Lester Tan and Anna Patricia Miravite


Exercise 8. Given a nested list extend it with adding sub list ["h", "i", "j"] in a such a way that it will look like the
following list

Exercise 9. Grade needed to pass

Kim wants to know what score she needs to get in her 4th exam to get a specific score given her previous 3 test
scores

make a program that asks for 4 inputs:


1st - 3rd input - test scores
4th input - her target score

then print
1. the grade that she needs to get in her 4th exam
2. convert her needed grade (the one you just computed) into letter grade

Impossible = greater than 100


A = 90-100
B = 80-89
C = 70 - 79
D = 60 - 69
F = less than 60

Exercise 10. J3j3 Fixer


Prepared by John Lester Tan and Anna Patricia Miravite 2
make a function that accepts a jeje string as input

the function should then fix the jeje string by


1. substituting letters to symbols/numbers
-@=a
-!=i
-5=s
-0=o
-^=v
-3=e
2. making the first letter of the word to uppercase while the others to lowercase

Example:

Input: 5@L5a
Output: Salsa

Exercise 11. Game Scorer

we want to build a game scorer which stores the scores in a list and at the end tells us who won

Assuming 3 games

1st input - name of the two team separated by a space


2nd input - score for team 1
3rd input - score for team 2
4th input - score for team 1
5th input - score for team 2
6th input - score for team 1
7th input - score for team 2
at the end, print the scores of team 1 and team 2 and who won

Example:

Exercise 12. String Locator

build a program that accepts 2 strings.

the first string is the string that we will be looking for in the second string

if string 1 exists in string 2, return 'Yehey'


if not, return 'Aww'

Do not use the in operator.

Prepared by John Lester Tan and Anna Patricia Miravite 3


Input:
kim
kimberly

Output:
Yehey

Input:
ik
kimberly

Output:
Aww

Exercise 13: Binary to Decimal Converter

make a program that takes a binary number as input and converts it to decimal

Sample:
Input:
101011

Output:
43

Do not use any modules

Exercise 14: Pig Latin

a made-up language formed from English by transferring the first letter of each word to the end of the word and
adding a vocalic syllable (-ay) so chicken soup would be translated to hickencay oupsay . Pig Latin is typically spoken
playfully, as if to convey secrecy.

create a pig latin encoder


it should accept a phrase and encode it into pig latin

Input:
hello there

Output:
ellohay heretay

Exercise 15 Making a matrix from inputs

Define a function that accepts the following as input:


Number of Rows
Number of Columns
List of all the elements of your matrix, written from left to right, top to bottom.
Example:
Input:
5
5
2, 3, 5, 8, 9, 12, 14, 23, 21, 67, 32, 35, 61, 17, 25, 54, 36, 87, 10, 21, 11, 4, 2, 5, 8

Output:
[[2, 3, 5, 8, 9], [12, 14, 23, 21, 67], [32, 35, 61, 17, 25], [54, 36, 87, 10, 21], [11, 4, 2, 5, 8]]

Prepared by John Lester Tan and Anna Patricia Miravite 4

You might also like