Skip to content

Commit

Permalink
update labs
Browse files Browse the repository at this point in the history
  • Loading branch information
rambasnet committed Sep 30, 2023
1 parent 75b6b5d commit 496a7ed
Show file tree
Hide file tree
Showing 14 changed files with 155 additions and 145 deletions.
17 changes: 9 additions & 8 deletions labs/dicts/morsecodepalindromes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ Write a Python program to solve the Kattis problem Morse Code Palindrome: [https

1. Open your CS0Lab-... repo in VS Code
2. Create a lab folder **morsecodepalindromes** inside your CS0Lab-... repository
3. Inside the lab folder, create two files: main.py and test_main.py
4. Type the partial code stub provided in main.py and test_main.py files and fix all FIXMEs. (80 points)
3. Inside the lab folder, create two files provided in the lab folder.
4. Type the partial code stub provided and fix all FIXMEs. (80 points)
5. Follow best programming practices by using proper white spaces, comments, etc.

```text
Expand All @@ -22,15 +22,16 @@ Kattis is a computer program that provides specific input and expects exact outp
6. Unittest all the important functions using pytest. Install pytest if required.

```bash
$ pytest --version
$ pip install -U pytest
$ pytest test_main.py
$ pytest --version
$ pip install -U pytest
$ pytest test_main.py
$ python -m pytest test_main.py
```

7. Test the whole program manually. While testing, provide input using the same format as described in the Input section and shown in input samples.
8. Upload only the main.py script to Kattis for testing. You can test your solution as many times as you wish. Kattis uses its own hidden test cases to test your program against. However, your goal is to get the accepted verdict in the first try.
8. Upload only the solution script to Kattis for testing. You can test your solution as many times as you wish. Kattis uses its own hidden test cases to test your program against. However, your goal is to get the accepted verdict in the first try.
9. Create screenshots showing your local testing and the kattis final Accept verdict and save them to the lab folder. (10 points)
10. Update your README file (10 points) as shown here: https://github.com/rambasnet/csci000-astudent
10. Update your README file (10 points) as shown here: [https://github.com/rambasnet/csci000-astudent](https://github.com/rambasnet/csci000-astudent)

## Submission

Expand All @@ -47,4 +48,4 @@ $ git push
$ git status
```

- Check and make sure the files are actually pushed to your GitHub repo on github.com.
- Check and make sure the files are actually pushed to your GitHub repo.
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@
Given english text, the program finds if the corresponding morse code is a palindrome.
Algorithm steps:
1. Create a dictionary to map alphabets and numbers to morse code
2. Read the input english string
3. Convert the string into upper case english string
4. Convert english string into Morse Code string using the dictionary
5. Check if the Morse Code string is a palindrome
i. Print 1 if it's a palindrome
ii Otherwise, print 0
1. Create a dictionary to map alphabets and numbers to morse code
2. Read the input english string
3. Convert the string into upper case english string
4. Convert english string into Morse Code string using the dictionary
5. Check if the Morse Code string is a palindrome
i. Print 1 if it's a palindrome
ii Otherwise, print 0
"""

import sys

# create English to Morse Code dictionary
Expand Down Expand Up @@ -88,14 +87,14 @@ def convert_to_morse(english: str) -> str:
return morse_code


def solve():
def solve() -> None:
# read/input english text as a line
english = input()
# FIXME 4: convert english into uppercase
upper_english = english
print(upper_english, file=sys.stderr)
morse_code = convert_to_morse(upper_english)
# FIXME 5 - call is_palindrome passing proper argument and print the result
# FIXME 5: call is_palindrome passing proper argument and print the result


if __name__ == '__main__':
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
"""Module to test functions in main.py
"""Module to test functions in morsecode.py
"""

import main
import morsecode


def test_convert_to_palindrome1():
actual_ans = main.convert_to_morse('AN')
actual_ans = morsecode.convert_to_morse('AN')
expected_ans = '.--.'
assert actual_ans == expected_ans

# FIXME 6 - write 3 more test cases to test convert_to_palindrome function


def test_ispalindrome1():
ans = main.is_palindrome('.--.')
ans = morsecode.is_palindrome('.--.')
expected = 1
assert ans == expected

Expand Down
16 changes: 8 additions & 8 deletions labs/lists/pet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ Write a Python program to solve the Kattis problem called pet: [https://open.kat
## Lab Instructions

1. Open your CS0Lab-... repo in VS Code
2. Create lab folder **pet** inside your CS0Lab-... repository
3. Inside the pet folder, create two files: main.py and test_main.py
4. Type the partial code stub provided in main.py and test_main.py files and fix all FIXMEs. (80 points)
2. Create lab folder **lists** inside your CS0Lab-... repository
3. Inside the pet folder, create two files: pet.py and test_pet.py
4. Type the partial code stub provided in the lab folder and fix all FIXMEs. (80 points)
5. Follow best programming practices by using proper white spaces, comments, etc.

```text
Expand All @@ -24,13 +24,14 @@ Kattis is a computer program that provides specific input and expects exact outp
```bash
$ pytest --version
$ pip install -U pytest
$ pytest test_main.py
$ pytest .
$ python -m pytest .
```

7. Test the whole program manually. While testing, provide input using the same format as described in the Input section and shown in input samples.
8. Upload only the .py scripts to Kattis for testing. You can test your solution as many times as you wish. Kattis uses its own hidden test cases to test your program against. However, your goal is to get the accepted verdict in the first try.
8. Upload only the solution script to Kattis for testing. You can test your solution as many times as you wish. Kattis uses its own hidden test cases to test your program against. However, your goal is to get the accepted verdict in the first try.
9. Create screenshots showing your local testing and the kattis final Accept verdict and save them to the lab folder. (10 points)
10. Update your README file (10 points) as shown here: https://github.com/rambasnet/csci000-astudent
10. Update your README file (10 points) as shown here: [https://github.com/rambasnet/csci000-astudent](https://github.com/rambasnet/csci000-astudent)

## Submission

Expand All @@ -46,5 +47,4 @@ $ git push
$ git status
```

- Check and make sure the files are actually pushed to your GitHub repo on github.com.
NOTE: Do not add and commit to this lab folder after the due date as it may be considered late submission!
- Check and make sure the files are actually pushed to your GitHub repo.
35 changes: 17 additions & 18 deletions labs/lists/pet/main.py → labs/lists/pet/pet.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@
Read and solve - Pet: https://open.kattis.com/problems/pet
Algorithm steps:
1. Create a list to store the total scores of each contestant
2. Repeat 5 times:
1. Read the input line
2. Split the line into a list of numbers
3. Convert the list of strings into a list of ints
4. Sum the list of ints
5. Append the sum to the list of scores
1. Create a list to store the total scores of each contestant
2. Repeat 5 times:
i. Read the input line
ii. Split the line into a list of numbers
iii. Convert the list of strings into a list of ints
iv. Sum the list of ints
v. Append the sum to the list of scores
3. Find the max score in the list of scores
4. Find the index of the max score in the list of scores
5. Print the index of the max score + 1 and the max score
"""

import sys

from typing import List


def main():
def main() -> None:
"""Main function that solves the problem
"""
# step 1. create a list to store the total scores of each contestant
Expand All @@ -35,20 +35,19 @@ def main():
# FIXME 5 - print the final output calling answer function


def get_data():
def get_data() -> List[int]:
"""Reads the data from std input and returns it as a list of ints
Args:
None
Returns:
List[int]: list of ints
"""
str_nums = input().split() # list of string numbers
# FIXME 6: convert str_nums int a list of ints and return it
pass
# FIXME 6: convert str_nums as list of ints and return it


def list_sum(numbers: List[int]):
"""Finds and returns sum of the numbers in the list
def list_sum(numbers: List[int]) -> int:
"""Finds and returns sum of the numbers in the list.
Args:
numbers: List[int]: # takes a list of numbers as a parameter
Expand All @@ -60,16 +59,16 @@ def list_sum(numbers: List[int]):
return ans


def answer(scores: List[int]):
"""Returns the index of the max score + 1 and the max score as a string
def answer(scores: List[int]) -> str:
"""Find and return the answer as a string.
Args:
scores (List[int]): List of 5 contestants scores
Returns:
str: index of the max score + 1 and the max score as a string
"""
max_score = max(scores)
index = scores.index(max_score)
# FIXME 8: return the index+1 and the max number in the list as a string
pass


if __name__ == "__main__":
Expand Down
34 changes: 0 additions & 34 deletions labs/lists/pet/test_main.py

This file was deleted.

38 changes: 38 additions & 0 deletions labs/lists/pet/test_pet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""Moduel to test important function in pet.py.
"""

import pet


def test_answer() -> None:
"""Tests answer function."""
ans = pet.answer([10, 20, 11, 15, 13])
expected = "2 20"
assert ans == expected, f"Expected: {expected}, but got: {ans}"


def test_answer2() -> None:
"""Tests answer function."""
ans = pet.answer([6, 10, 8, 4, 15])
expected = "5 15"
assert ans == expected, f"Expected: {expected}, but got: {ans}"

# FIXME 1: add a test case function to test answer function
# FIXME 2: add a test case function to test answer function


def test_list_sum() -> None:
"""Tests list_sum function."""
ans = pet.list_sum([6, 7, 8, 10])
expected = 31
assert ans == expected, f"Expected: {expected}, but got: {ans}"


def test_list_sum2() -> None:
"""Tests list_sum function."""
ans = pet.list_sum([2, 3, 4, 5])
expected = 14
assert ans == expected, f"Expected: {expected}, but got: {ans}"

# FIXME 3: add a test case function to test list_sum function
# FIXME 4: add a test case function to test list_sum function
10 changes: 5 additions & 5 deletions labs/loops/oddities/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ Write a Python program to solve the Kattis problem - Oddities [https://open.katt

1. Open your CS0Lab-... repo in VS Code
2. Create lab folder **oddities** inside your CS0Lab-... repository
3. Inside the lab folder, create two files: main.py and test_main.py
4. Type the partial code stub provided in main.py and test_main.py files and fix all FIXMEs. (80 points)
3. Inside the lab folder, create two files.
4. Type the partial code stub provided and fix all FIXMEs. (80 points)
5. Follow best programming practices by using proper white spaces, comments, etc.

```note
Expand All @@ -24,12 +24,12 @@ Kattis is a computer program that provides specific input and expects exact outp
```bash
$ pytest --version
$ pip install -U pytest
$ pytest test_main.py
$ python -m pytest test_main.py
$ pytest .
$ python -m pytest .
```

7. Test the whole program manually. While testing, provide input using the same format as described in the Input section and shown in input samples.
8. Upload only the .py scripts to Kattis for testing. You can test your solution as many times as you wish. Kattis uses its own hidden test cases to test your program against. However, your goal is to get the accepted verdict in the first try.
8. Upload only the solution script to Kattis. You can test your solution as many times as you wish. Kattis uses its own hidden test cases to test your program against. However, your goal is to get the accepted verdict in the first try.
9. Create screenshots showing your local testing and the kattis final Accept verdict and save them to the lab folder. (10 points)
10. Update your README file (10 points) as shown here: [https://github.com/rambasnet/csci000-astudent](https://github.com/rambasnet/csci000-astudent)

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,39 +1,42 @@
"""Test cases for main.py"""
import main
"""Test cases for oddities.py"""
import oddities


def test_answer():
"""Test answer function."""
ans = main.answer(10)
ans = oddities.answer(10)
expected = "10 is even"
assert ans == expected, f"Expected: {expected}, but got: {ans}"


def test_answer2():
"""Test answer function for negavitve odd number."""
ans = main.answer(-199)
ans = oddities.answer(-199)
expected = "-199 is odd"
assert ans == expected, f"Expected: {expected}, but got: {ans}"


# FIXME 6: add a new test case function to test your answer function

# FIXME 7: add a new test case function to test your answer function


def test_odd_even():
"""Test odd_even function.
"""
ans = main.odd_even(10)
ans = oddities.odd_even(10)
expected = "even"
assert ans == expected, f"Expected: {expected}, but got: {ans}"


def test_odd_even2():
"""Test odd_even function for negavitve odd number
"""
ans = main.odd_even(-199)
ans = oddities.odd_even(-199)
expected = "odd"
assert ans == expected, f"Expected: {expected}, but got: {ans}"


# FIXME 8: add a new test case function to test your answer function

# FIXME 9: add a new test case function to test your answer function
Loading

0 comments on commit 496a7ed

Please sign in to comment.