Starting from:

$30

Introduction to Programming Laboratory I Quiz 3


BBM 103: Introduction to Programming Laboratory I
Quiz 3
Subject: Loops, conditional statements, basic arithmetic operations, lists and their
functions

Introduction
In this quiz, we expect you all to get practice on basic python commands, and also get experience with the programming environments, the user interface of the Integrated Development
Environment (or IDE), python programming console, or terminal. This quiz consists of two
separate parts Problem1 and Problem2. You should handle each problem in a separate .py
file and name it with the problem index; i.e., your solution should be named quiz3-1.py for
the problem1.
0.1 Problem1: Sum of digits of x raised to n
For some x
n
, find the sum of its digits until there is only a one digit. The order of commandline arguments:
python3 quiz3-1.py a b =>python3 quiz3-1.py 2 5
Output : 2ˆ5 = 32 = 3 + 2 = 5
python3 quiz3-1.py 5 3
Output : 5ˆ3 = 125 = 1 + 2 + 5 = 8
python3 quiz3-1.py 2 8
Output : 2ˆ8 = 256 = 2 + 5 + 6 = 13 = 1 + 3 = 4
0.2 Problem2: Lucky Number
A Lucky Number is a natural number in a set which is generated by a certain sieve. This sieve
is similar to the Sieve of Eratosthenes that generates the primes, but it eliminates numbers
based on their position in the remaining set, instead of their value (or position in the initial
set of natural numbers). The set of lucky numbers is taken from command line:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
Starting with 1, remove every other element from this set. We are left with:
1 3 5 7 9 11 13 15 17 19 21
After 1, the next number in the set is 3. So, remove every 3rd number. Clearly, 5 is removed because it’s the third number in the above set. Go on and keep removing every 3rd
number.
1
Fall 2021
BBM 103: Introduction to Programming Laboratory I
Your new set is:
1 3 7 9 13 15 19 21
Here, the next remaining number you have after 3 is 7. Now, at this point, it’s obvious that
there’s no way 1 and 3 are ever getting eliminated. Thus, we can conclude that 1 and 3 are
lucky numbers.
Now remove every 7th number. Clearly, 19 would be the first to be wiped out. This process
continues until the list size is less than the defined number. You’re left with:
1 3 7 9 13 15 21
Note: Your program should discard the numbers less than zero! The order of command-line
arguments:
python3 quiz3-2.py "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22"
Output : 1 3 7 9 13 15 21
General Notes
• Do not miss the submission deadline.
• Save all your work until the quiz is graded.
• Compile your code on dev.cs.hacettepe.edu.tr before submitting your work to make sure
it compiles without any problems on our server.
• You can ask your questions via Piazza and you are supposed to be aware of everything
discussed on Piazza.
• You must submit your work with the file hierarchy as stated below:
→ <quiz3-1.py>
→ <quiz3-2.py>
2