Skip to content

Commit bf5ede7

Browse files
author
Holladworld
committed
Readme updated
1 parent 2f3d6cd commit bf5ede7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+470
-18
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/python3
2+
for i in range(122, 96, -1): # ASSCI code in reverse for lowercase
3+
if i % 2:
4+
i -= 32
5+
print("{:c}".format(i), end="")
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/python3
2+
def magic_calculation(a, b, c):
3+
if a < b:
4+
return(c)
5+
if c > b:
6+
return a + b
7+
return a * b - c
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env python3
2+
pow = __import__('11-pow').pow
3+
4+
print(pow(2, 2))
5+
print(pow(98, 2))
6+
print(pow(98, 0))
7+
print(pow(100, -2))
8+
print(pow(-4, 5))
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env python3
2+
fizzbuzz = __import__('12-fizzbuzz').fizzbuzz
3+
4+
fizzbuzz()
5+
print("")
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <stdlib.h>
2+
#include <string.h>
3+
#include <stdio.h>
4+
#include "lists.h"
5+
6+
/**
7+
* main - check the code for
8+
*
9+
* Return: Always 0.
10+
*/
11+
int main(void)
12+
{
13+
listint_t *head;
14+
15+
head = NULL;
16+
add_nodeint_end(&head, 0);
17+
add_nodeint_end(&head, 1);
18+
add_nodeint_end(&head, 2);
19+
add_nodeint_end(&head, 3);
20+
add_nodeint_end(&head, 4);
21+
add_nodeint_end(&head, 98);
22+
add_nodeint_end(&head, 402);
23+
add_nodeint_end(&head, 1024);
24+
print_listint(head);
25+
26+
printf("-----------------\n");
27+
28+
insert_node(&head, 27);
29+
30+
print_listint(head);
31+
32+
free_listint(head);
33+
34+
return (0);
35+
}
Binary file not shown.
Binary file not shown.
16.7 KB
Binary file not shown.
Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
#!/usr/bin/python3
22
if __name__ == "__main__":
3-
import sys
3+
4+
"""Handle basic arithmetic operations."""
45
from calculator_1 import add, sub, mul, div
5-
num_arg = len(sys.argv) - 1
6-
if num_arg < 3:
7-
print("Usage: ./100-my_calculator.py <a> <operator> <b>")
8-
exit(1)
9-
a, operator, b = sys.argv[1:]
10-
if operator not in "+-*/":
11-
print("Unknown operator. Available operators: +, -, * and /")
6+
import sys
7+
numm = len(sys.argv) - 1
8+
if numm < 3:
9+
print("Usage:./100-my_calculator.py <a> <operator> <b>")
1210
exit(1)
13-
print("{:s} {:s} {:s} = ".format(a, operator, b), end="")
14-
for ope, func in [('+', add), ('-', sub), ('*', mul), ('/', div)]:
15-
if operator == ope:
16-
print("{:d}".format(func(int(a), int(b))))
11+
operators = {"+": add, "_": sub, "*": mul, "/": div}
12+
if sys.argv[2] not in list(operators.keys()):
13+
print("Unknown operator. Available operators: +, -, * and /")
14+
exit(1)
15+
16+
a = int(sys.argv[1])
17+
b = int(sys.argv[3])
18+
print("{} {} {} = {}".format(a, sys.argv[2], b, operator[sys.argv[2]](a, b)))
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/python3
2+
a = 98
3+
"""Simple variable
4+
"""
Binary file not shown.

0x03-python-data_structures/0-main.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/python3
2+
print_list_integer = __import__('0-print_list_integer').print_list_integer
3+
4+
my_list = [1, 2, 3, 4, 5]
5+
print_list_integer(my_list)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/python3
2+
divisible_by_2 = __import__('10-divisible_by_2').divisible_by_2
3+
4+
my_list = [0, 1, 2, 3, 4, 5, 6]
5+
list_result = divisible_by_2(my_list)
6+
7+
i = 0
8+
while i < len(list_result):
9+
print("{:d} {:s} divisible by 2".format(my_list[i], "is" if list_result[i] else "is not"))
10+
i += 1
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <stdlib.h>
2+
#include <stdio.h>
3+
#include <Python.h>
4+
/**
5+
* print_python_list_info - function that prints some basic
6+
* info about Python lists
7+
* @p: python list
8+
*/
9+
void print_python_list_info(PyObject *p)
10+
{
11+
int elem;
12+
13+
printf("[*] Size of the Python List = %lu\n", Py_SIZE(p));
14+
printf("[*] Allocated = %lu\n", ((PyListObject *)p)->allocated);
15+
for (elem = 0; elem < Py_SIZE(p); elem++)
16+
printf("Element %d: %s\n", elem, Py_TYPE(PyList_GetItem(p, elem))->tp_name);
17+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/python3
2+
delete_at = __import__('11-delete_at').delete_at
3+
4+
my_list = [1, 2, 3, 4, 5]
5+
idx = 3
6+
new_list = delete_at(my_list, idx)
7+
print(new_list)
8+
print(my_list)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include "lists.h"
2+
#include <stdlib.h>
3+
#include <stdio.h>
4+
5+
/**
6+
*add_nodeint - adds a new node at the beginning of a listint_t list
7+
*@head: head of listint_t
8+
*@n: int to add in listint_t list
9+
*Return: address of the new element, or NULL if it failed
10+
*/
11+
listint_t *add_nodeint(listint_t **head, const int n)
12+
{
13+
listint_t *new;
14+
15+
new = malloc(sizeof(listint_t));
16+
if (new == NULL)
17+
return (NULL);
18+
new->n = n;
19+
new->next = *head;
20+
*head = new;
21+
return (new);
22+
}
23+
/**
24+
*is_palindrome - identify if a syngle linked list is palindrome
25+
*@head: head of listint_t
26+
*Return: 1 if it is palindrome else 0
27+
*/
28+
int is_palindrome(listint_t **head)
29+
{
30+
listint_t *head2 = *head;
31+
listint_t *aux = NULL, *aux2 = NULL;
32+
33+
if (*head == NULL || head2->next == NULL)
34+
return (1);
35+
while (head2 != NULL)
36+
{
37+
add_nodeint(&aux, head2->n);
38+
head2 = head2->next;
39+
}
40+
aux2 = aux;
41+
while (*head != NULL)
42+
{
43+
if ((*head)->n != aux2->n)
44+
{
45+
free_listint(aux);
46+
return (0);
47+
}
48+
*head = (*head)->next;
49+
aux2 = aux2->next;
50+
}
51+
free_listint(aux);
52+
return (1);
53+
}

0x03-python-data_structures/2-main.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/python3
2+
replace_in_list = __import__('2-replace_in_list').replace_in_list
3+
4+
my_list = [1, 2, 3, 4, 5]
5+
idx = 3
6+
new_element = 9
7+
new_list = replace_in_list(my_list, idx, new_element)
8+
9+
print(new_list)
10+
print(my_list)

0x03-python-data_structures/3-main.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/python3
2+
print_reversed_list_integer = __import__('3-print_reversed_list_integer').print_reversed_list_integer
3+
4+
my_list = [1, 2, 3, 4, 5]
5+
print_reversed_list_integer(my_list)

0x03-python-data_structures/4-main.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/python3
2+
new_in_list = __import__('4-new_in_list').new_in_list
3+
4+
my_list = [1, 2, 3, 4, 5]
5+
idx = 3
6+
new_element = 9
7+
new_list = new_in_list(my_list, idx, new_element)
8+
9+
print(new_list)
10+
print(my_list)

0x03-python-data_structures/5-main.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env python3
2+
no_c = __import__('5-no_c').no_c
3+
4+
print(no_c("Best School"))
5+
print(no_c("Chicago"))
6+
print(no_c("C is fun!"))

0x03-python-data_structures/6-main.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/python3
2+
print_matrix_integer = __import__('6-print_matrix_integer').print_matrix_integer
3+
4+
matrix = [
5+
[1, 2, 3],
6+
[4, 5, 6],
7+
[7, 8, 9]
8+
]
9+
10+
print_matrix_integer(matrix)
11+
print("--")
12+
print_matrix_integer()

0x03-python-data_structures/7-main.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/python3
2+
add_tuple = __import__('7-add_tuple').add_tuple
3+
4+
tuple_a = (1, 89)
5+
tuple_b = (88, 11)
6+
new_tuple = add_tuple(tuple_a, tuple_b)
7+
print(new_tuple)
8+
9+
print(add_tuple(tuple_a, (1, )))
10+
print(add_tuple(tuple_a, ()))

0x03-python-data_structures/8-main.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/python3
2+
multiple_returns = __import__('8-multiple_returns').multiple_returns
3+
4+
sentence = "At school, I learnt C!"
5+
length, first = multiple_returns(sentence)
6+
print("Length: {:d} - First character: {}".format(length, first))

0x03-python-data_structures/9-main.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/python3
2+
max_integer = __import__('9-max_integer').max_integer
3+
4+
my_list = [1, 90, 2, 13, 34, 5, -13, 3]
5+
max_value = max_integer(my_list)
6+
print("Max: {}".format(max_value))
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
7.9 KB
Binary file not shown.

0x03-python-data_structures/lists.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#ifndef LISTS_H
2+
#define LISTS_H
3+
#include <stdio.h>
4+
5+
/**
6+
* struct listint_s - singly linked list
7+
* @n: integer
8+
* @next: points to the next node
9+
*
10+
* Description: singly linked list node structure
11+
* for Holberton project
12+
*/
13+
typedef struct listint_s
14+
{
15+
int n;
16+
struct listint_s *next;
17+
} listint_t;
18+
19+
size_t print_listint(const listint_t *h);
20+
listint_t *add_nodeint_end(listint_t **head, const int n);
21+
void free_listint(listint_t *head);
22+
23+
int is_palindrome(listint_t **head);
24+
25+
#endif /* LISTS_H */
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/python3
2+
print_list_integer = __import__('0-print_list_integer').print_list_integer
3+
4+
my_list = [1, 2, 3, 4, 5]
5+
print_list_integer(my_list)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/python3
2+
element_at = __import__('1-element_at').element_at
3+
4+
my_list = [1, 2, 3, 4, 5]
5+
idx = 3
6+
print("Element at index {:d} is {}".format(idx, element_at(my_list, idx)))
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import ctypes
2+
3+
lib = ctypes.CDLL('./libPyList.so')
4+
lib.print_python_list_info.argtypes = [ctypes.py_object]
5+
l = ['hello', 'World']
6+
lib.print_python_list_info(l)
7+
del l[1]
8+
lib.print_python_list_info(l)
9+
l = l + [4, 5, 6.0, (9, 8), [9, 8, 1024], "Holberton"]
10+
lib.print_python_list_info(l)
11+
l = []
12+
lib.print_python_list_info(l)
13+
l.append(0)
14+
lib.print_python_list_info(l)
15+
l.append(1)
16+
l.append(2)
17+
l.append(3)
18+
l.append(4)
19+
lib.print_python_list_info(l)
20+
l.pop()
21+
lib.print_python_list_info(l)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/python3
2+
delete_at = __import__('11-delete_at').delete_at
3+
4+
my_list = [1, 2, 3, 4, 5]
5+
idx = 3
6+
new_list = delete_at(my_list, idx)
7+
print(new_list)
8+
print(my_list)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include "lists.h"
4+
5+
/**
6+
* main - check the code for Holberton School students.
7+
*
8+
* Return: Always 0.
9+
*/
10+
int main(void)
11+
{
12+
listint_t *head;
13+
14+
head = NULL;
15+
add_nodeint_end(&head, 1);
16+
add_nodeint_end(&head, 17);
17+
add_nodeint_end(&head, 972);
18+
add_nodeint_end(&head, 50);
19+
add_nodeint_end(&head, 98);
20+
add_nodeint_end(&head, 98);
21+
add_nodeint_end(&head, 50);
22+
add_nodeint_end(&head, 972);
23+
add_nodeint_end(&head, 17);
24+
add_nodeint_end(&head, 1);
25+
print_listint(head);
26+
27+
if (is_palindrome(&head) == 1)
28+
printf("Linked list is a palindrome\n");
29+
else
30+
printf("Linked list is not a palindrome\n");
31+
32+
free_listint(head);
33+
34+
return (0);
35+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/python3
2+
replace_in_list = __import__('2-replace_in_list').replace_in_list
3+
4+
my_list = [1, 2, 3, 4, 5]
5+
idx = 3
6+
new_element = 9
7+
new_list = replace_in_list(my_list, idx, new_element)
8+
9+
print(new_list)
10+
print(my_list)

0 commit comments

Comments
 (0)