0% found this document useful (0 votes)
6 views13 pages

Lab Exam PYHTON

The document is a question bank for the AETN2302 Lab Exam for Fall 2023, containing various programming scenarios. Each scenario requires students to implement specific coding tasks, such as creating lists, performing calculations, and manipulating strings. The exam is individual, and students are restricted to using course materials and a sandbox for coding, with no collaboration allowed.

Uploaded by

khadegaalaskari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views13 pages

Lab Exam PYHTON

The document is a question bank for the AETN2302 Lab Exam for Fall 2023, containing various programming scenarios. Each scenario requires students to implement specific coding tasks, such as creating lists, performing calculations, and manipulating strings. The exam is individual, and students are restricted to using course materials and a sandbox for coding, with no collaboration allowed.

Uploaded by

khadegaalaskari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

AETN2302 Lab Exam Question Bank Fall 2023

Instructions:

Time: 30 min.

a) Carefully read the scenario.


b) Then provide some kind of planning: flowchart or pseudocode or step-by-step explanation.
c) Write the code in the sandbox and debug it. Once you make sure this is correct, write it down in
the space provided.
d) Provide the output for input(s) of your interest.
e) Once done, ask the instructor to verify your work and hand in the paper.

Please note that:

1- The test is individual. No collaboration (as done in labs) is allowed.


2- You may use NetAcad course material and sandbox to run and debug the program, no other
tools are allowed (google, ChatGPT, etc).
3- If your code contains commands/functions that are not covered in the class, it will not be
accepted.

1- Scenario: You are given a list of integers containing duplicate elements. The task is to generate a
second list, which contains only the duplicate elements. In simple words, the new list should contain
elements that appear no more than once. Write code that takes input from a user, creates a list and
then prints the cleaned-up list as output.

Example: Input_list = [10, 20, 30, 20, 20, 30, 40, 50, -20, 60, 60, -20, -20]

Output : output_list = [20, 30, -20, 60]

2- Scenario: Write a program to check a number that is inputted by the user then checks whether the
number entered by the user is positive, negative or zero.
3- Scenario: Write a program that accepts 3 integers as input and stores them as a list. Then write a
function that accepts this list and returns the sum of the squares of the 3 numbers as the output. Then
call the function in the code and it prints the output of that function.

Example: Input: 1,2,3 Output: 14 (i.e., 12+22+32=14)

4- Scenario: Write a program that accepts 3 integers as input and stores them as a list. Then write a
function that accepts this list and takes 2 to the power of each element. Then it returns the sum of
them as the output. Then call the function in the code and print the output of that function.

Example: Input: 1,2,3 Output: 14 (i.e., 21+22+23=14)

5- Scenario: Write a program that gets integer N as input and generates the sum of (0.5) i for i from 1 to
N. Try different values of N and check if the value can get larger than 1 or not.

Example: Input: N=5, Output: 0.96875

(i.e., (0.5)1+(0.5)2+(0.5)3+(0.5)4+(0.5)5 = 0.96875)


6- Scenario: Write a program that accepts a string and removes any “.” from that string. If there is no
“.”, print ‘There is no “.” ’.

Example: Input: “This is a test. Just try it.” Output: “This is a test Just try it”

7- Scenario: Write a program that accepts a string and replaces any “.” With “!”. from that string. If
there is no “.”, print ‘There is no “.” ’.

Example: Input: “This is a test. Just try it.” Output: “This is a test! Just try it!”

8- Scenario: Write a program that accepts 2 lists of 5 integers each from the user and compares them. If
they are equal, it prints “the same” and if not, it prints “different”

Example: Input: [1 2 3 4 5], [1 5 3 4 5] Output: “different”


9- Scenario: Write a program that accepts a list of integers as input and checks whether it contains the
number “2”. If this is the case, it should print the location in the list. If not, it prints “There is no
number 2 in the list”. Note: If there is more than one “2”, the location of the first “2” has to be
printed.

Example: Input: [1 3 2 4 5 2], Output: position 3

10- Scenario: Write a program that accepts a list of integers as input and checks whether it contains the
number “2”. If this is the case, it should print the location in the list. If not, it prints “There is no
number 2 in the list”. Note: If there is more than one “2”, the location of the last “2” has to be printed.

Example: Input: [1 3 2 4 5 2], Output: position 5


11- Scenario: Write a program that accepts a list of characters as input and then determines how many
times the letter “A” is repeated. It should then print “Letter A is repeated … times” where “…” shows
the number of repetitions. If there is no “A”, it prints: “There was no letter A”

Example: Input: [A B C A E], Output: Letter A is repeated 2 times

12- Scenario: Write a program that accepts a list of integers. Have it create a new list that contains only
those numbers that are squares of an integer. This number should then be printed. If there is no such
a number, it prints “none”. Hint: if the square root of a number is an integer, it means that it can be
square of another integer, for example 160.5 is an integer but 150.5 is not an integer.

Example: Input: [1 5 8 16 9], Output: [1 16 9]


13- Scenario: Write a program that accepts a list of integers. Have it create a new list that contains only
those numbers that are even and then prints it. If there is no such number, it then prints: “none”.

Example: Input: [1 5 8 16 9], Output: [8 16]

14- Scenario: Write a program that accepts a list of integers. Have it create a new list that contains only
those numbers that are odd and then prints it. If there is no such a number, it then prints: “none”.

Example: Input: [1 5 8 16 9], Output: [1 5]


15- Scenario: Write a program that accepts a list of integers. Have it create a new list that contains only
those integers that are divisible by 3 and then prints it. If there is no such a number, it then prints
“none”.

Example: Input: [1 5 8 16 9], Output: [9]

16- Scenario: Write a program that accepts a list of integers. Have it create a new list that contains only
those that are non-negative and then it prints it. If there is no such a number, it then prints: “none”.

Example: Input: [0 5 8 -16 -9], Output: [0 5 8]


17- Scenario: Write a program that accepts a list of integers. Have it create a new list by using the
following formula on each element of the input list: Y=1/X. If the list contains integer 0, skip it. In
this case the output list will be shorter.

Example: Input: [0 1 2 4], Output: [1 0.5 0.25]

18- Scenario: Write a program that accepts the integer N and prints the sum of the numbers from 1 to N.
If N is negative or zero, it should print: “Input Error”.

Example: Input: N = 4, Output: 1+2+3+4 = 10


19- Scenario: Write a program that accepts the integer N and prints the product of the numbers from 1 to
N. If N is negative or zero, it should print: “Input Error”.

Example: Input: N = 4, Output: 1*2*3*4 = 24

20- Scenario: Write a program that accepts the coefficients of a quadratic equation x 2+ax+b = 0 and
prints the roots as output. If there are no real roots, it prints “The equation has no roots”.

Note: In order for the equation to have real roots, D=a2-4b has to be non-negative. If this is the
case, the roots are (-a+D0.5)/2 and (-a-D0.5)/2

Example: Input: a = -5, b = 6, Output: x = 2 and 3

21- Scenario: Write a program that accepts a list L as input. If the length of L is an even number, then
define 2 lists: L1 and L2 and then copy the first half of L to L1 and the 2nd half of L to L2. If the
length of the list is not even, print “I can not break the list in half”.
Example: Input: L=[1 3 2 4 6 7 5 2], Output: L1=[1 3 2 4], L2=[6 7 5 2].

22- Scenario: Write a program that accepts a list L as input. If the length of L is an even number, define 2
tuples T1 and T2 and copy the first half of L to T1 and 2nd half of L to T2. If the length of the list is
not even, print “I cannot break the list into half”.

Example: Input: L=[1 3 2 4 6 7 5 2], Output: T1=(1 3 2 4), T2=(6 7 5 2).

23- Scenario: Write a program that accepts a list L as input which contains a list of student weights in
Kilograms and converts them into Pounds. Print the individual weights in pounds and calculate the
total weight of all student in both Kg and pounds.

Example: Input: [50 100 70 80], Output: [110 220 154 176], Total_in_pounds=660, Total_in_Kg= 300

24- Scenario: Write a program that accepts list L1 of length 4 that contains the names of people and list
L2 of the same length that contains the phone numbers of these people. Then create a dictionary of
this data with the name as keys and phone number as values. Then print out the dictionary.

A sample output: {‘Mo’ : 56789129, ‘Nick’ : 31553082, ‘Bob’ : 31553067, ‘Khaled’ : 33224455}

25- Scenario: Write a program to print the first 10 multipliers of a given number.

Example: Input: 3
Output:
1x3=3
2x3=6
3x3=9
4 x 3 = 12
5 x 3 = 15
6 x 3 = 18
7 x 3 = 21
8 x 3 = 24
9 x 3 = 27
10 x 3 = 30

26 - Scenario: Write a program to count the total number of digits in a number.

Example: Input: 129475 Output: 6


27- Scenario: Write a program to check if the given string is a “palindrome”, meaning that the string and
reverse string are same and then print “It’s a Palindrome” or (‘NOT”)

Example: Input: RADAR Output: “It’s a Palindrome”

28- Scenario: Write a program to check if a given number is an Armstrong number, i.e., when each of its
digits is raised to the power of the number of digits in the number, it equals itself. For example, 153=1**3
+ 5**33 + 3**3 , is an Armstrong number.

Example: Input: 153 Output: “153 is an Armstrong number”

29- Scenario: Write a program to create a list of tuples having first element as the number and the second
element as the cube of the number.

Example: Input: [1,2,3] Output: [(1,1), (2,8), (3,27)]

30- Scenario: Given a list of numbers, the task is to write a python program to find the second largest
number in the given list.

Example: Input: [10,20,4] Output:10


31- Scenario: Write a python program to display all integers within the range 100-130 whose sum of
digits is an even number. For example, for 112 , 1+1+2 =4, which is an even number.
So the output is: 101, 103, 105, 107, 109, 110, 112, 114, 116, 118, 121, 123, 125, 127, 129

32- Scenario: Write a function that accepts 2 lists, each of length 3. The first list elements are inputs
from the user, they all should be strings and represent names. The second list elements are inputs from the
user, they all should be strings and represent nicknames. The Function should return a list where each
element is the combination of the names and nicknames.
Example: Input: [“John”, “Mary”, “Bob”], [“nice”, “beautiful”, “brave”]. Output: [“John the nice”, “Mary
the beautiful”, “Bob the brave”]

33- Scenario: Write a program that calculates the efficiency of light bulb and then output its energy
rating.
The program asks the user to enter two values: The light bulb output (in lumens, lm) and the power
consumption of the light bulb over 1000hour (in kW/1000h). Then by dividing them, it finds out the
efficiency ratio and reports the rating according to table below.
Energy rating Efficiency ratio
A 210 or above
B 185 or above
C 160 or above
D 135 or above
E 110 or above
F 85 or above
G Below 85

Example: Input: light bulb output = 12000 lm, power consumption = 45 kW/1000h
Output: the efficiency ratio = 266.6, Energy Ratio = A

34- Scenario: Write a program which will accept an integer number “n” from the user and then creates
and prints a dictionary that contains (i, i**3) for all numbers between 1 and n.
Example: Input: 6, Output: {1:1, 2:8, 3:27, 4:64, 5:125, 6:216}

You might also like