0% found this document useful (0 votes)
9 views4 pages

Coding Test

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)
9 views4 pages

Coding Test

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/ 4

Computer Science Test

1. Create a program that:


a. Set a list of [9,1,2,0,3,-4,5,6,7,0,-1,7,-9,9,10,0] (Use this list)
b. For each number, the program must check and count how many are positive, how
many are negative, how many are even, how many are odd, how many are zero.
(zero is not considered as odd or even number or positive or negative).

2. Create a program that:


a. Prompts the user to enter a year.
b. Checks whether the year is a leap year or not, using the following rules:

c. Display a message:
i. “Leap Year” if the year meets the criteria,
ii. “Not a Leap
Year” otherwise.
Example:
Input: 2000 → output: Leap Year (2000 is divisible by 4 and divisible by 100 but also divisible
by 400)
Input: 1800 → output: Not a Leap Year (1800 is divisible by 4, and divisible by 100 but not
divisible by 400
Input: 2024 → output: Leap Year (2024 is divisible by 4 and not divisible by 100)

3. Create a program that:


a. Prompts the user to input a Positive integer N.
b. Prints the number from 1 to N.
c. The output must alternate in sign: the first number is positive, the second is
negative, the third is negative and so on ..
Input: 5
Output: 1 -2 3 -4 5

4. Create a program that:


a. Accept three inputs: coefficient a, b, and c of a quadratic equations 𝑎𝑥2 + 𝑏𝑥 +
𝑐 = 0.
b. Calculates the discriminant using formula of 𝑏2 − 4. 𝑎. 𝑐
c. Based on the result in step b, determines the root types:
i. If the result is bigger than 0, display “Two distinct real roots”
ii. If the result is smaller than 0, display “Two complex (imaginary) roots
iii. If the result = 0, display “ One repeated root”

5. Buat program yang mencari pasangan dari sebuah angka target yang dimasukkan oleh user,
lalu menemukan semua pasangan angka unik di dalam list yang jika dijumlahkan sama
dengan target tersebut.
Tidak boleh menghitung pasangan yang urutannya terbalik (misal (3, 7) sama dengan (7, 3)).
Gunakan nested loop dan if untuk memeriksa pasangan. Gunakan List angka yang sudah
tersedia. Jika tidak ada pasangannya maka munculkan notifikasi “Pasangan angka tidak ada
yang sama dengan Target”.

Contoh Input:
list_angka = [2, 4, 3, 7, 5, 8, 1,15,19,13,12,11,10]
target = 9

Output:
Pasangan dengan jumlah 9:
(2, 7)
(4, 5)
(8, 1)

Target = 100
Pasangan tidak ada yang sama dengan Target.

6. Diberikan sebuah list 2D (matriks 3x3) yang berisi angka 1–9 untuk diperiksa.

Buat program yang memeriksa apakah setiap angka di baris dan kolom berbeda (tidak ada
angka yang sama).

Gunakan nested loop untuk memeriksa baris dan kolom.


Gunakan if untuk menentukan apakah ada duplikasi.
Jika valid → cetak "Sudoku Valid", jika tidak → cetak "Sudoku Tidak Valid".

Sudoku1 = [
[4, 8, 3],
[9, 2, 7],
[6, 1, 5]
]

Output: Sudoku Valid

Sudoku2 = [
[12, 8, 3],
[9, 2, 7],
[6, 1, 5]
]
Output: Sudoku Tidak Valid

Sudoku3 = [
[1, 8, 3],
[9, 2, 1],
[6, 1, 5]
]
Output: Sudoku Tidak Valid
Sudoku4 = [
[2, 8, 3],
[2, 4, 1],
[6, 7, 5]
]
Output: Sudoku Tidak Valid

Sudoku4 = [
[1, 8, 3],
[2, 2, 2],
[6, 7, 5]
]
Output: Sudoku Tidak Valid

7. Construct a program that stores several commands from the users such as ‘print’, ‘read’,
‘input’, ‘output’, ‘exit’, ‘undo’. All the command will be stored in one dimensional array
named ‘command’.
When the user types unknown commands then display “Unknown command”. If the user
types ‘exit’ then the program exits and displays all the commands that user has written. If
the user types ‘undo’ then 1 previous command will be deleted from the array. If user
undoes the command that the array is empty then give the display “No command in the
array”

Input:
undo
No command in the array
print
read
read
undo
undo
show
Unknown command
print
output
input
exit
(then it will print the remaining data in array)
print
print
output

then program terminates successfully


8. Construct a program to print a triangle of the first n rows where each row contains only
prime numbers in increasing order. Only need 1 input.
For n= 4, the output will be:

2
35
7 11 13
17 19 23 29

9. Print a checkboard pattern of characters with size n x n, where:


a. Cells in even rows and even columns get ‘X’
b. Cells in odd rows and odd columns get ‘0’
c. Else print ‘-‘
d. The input is only n

For n=6, the output will be:

X–X–X–

–O–O–O

X–X–X–

–O–O–O

X–X–X–

–O–O–O

10. Construct a program to print this pattern


For N=5, it means it will print 5 rows. In each row, there will be 1 in each side. The middle
number is an addition from two numbers from the upper row

1
11
1 2 1 (2 is addition from 1 and 1)
1 3 3 1 (3 is addition from 1 and 2 from upper row; 3 is addition from 2 and 1)
14641

You might also like