Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions data-processing-io.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
---
title: Product of Prime Numbers from User Input
tags: [primes, I/O, filtering]
---

# Problem Statement

Given five numbers input by the user, determine which of them are prime numbers. Find the product of the prime numbers and print it.

Assume the numbers are non-negative integers. If no prime numbers are found, print 0.

# Solution
```python test.py -r 'python test.py'
<template>
<sol>
def is_prime(n):
if n <= 1:
return False
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
return False
return True

nums = list(map(int, input().split()))
prime_nums = [num for num in nums if is_prime(num)]

if prime_nums:
product = 1
for prime in prime_nums:
product *= prime
print(product)
else:
print(0)
</sol>
</template>
```
# Public Test Cases

## Input 1
```
1 2 3 4 5
```

## Output 1
```
30
```

## Input 2
```
10 15 18 7 4
```

## Output 2
```
7
```

# Private Test Cases


## Input 1
```
6 9 11 13 17
```

## Output 1
```
2002
```

## Input 2
```
29 34 37 40 42
```

## Output 2
```
1073
```
152 changes: 152 additions & 0 deletions data-processing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
---
title: Data Processing Operations
tags: ['list', 'filter', 'map']
---

# Problem Statement

Write a function `process_numbers(input_list: list[int]) -> int` that takes a list of integers as input. The function should:

1. **Filter out the negative numbers** from the list.
2. **Double the remaining values** in the list.
3. **Find the unique values** after doubling.
4. **Calculate and return the sum** of the unique doubled values.

### Constraints:
- The input list will be non-empty.
- The list will contain only integers (both positive and negative).

### Examples:

`process_numbers([1, -3, 4, 2, -5, 2])` should return `14` (after filtering, doubling, finding unique values, and summing).

`process_numbers([1, 2, 3, -4, -5, 3])` should return `18` (after filtering, doubling, finding unique values, and summing).

`process_numbers([10, 10, -5, -5, 7])` should return `34` (after filtering, doubling, finding unique values, and summing).

`process_numbers([-1, -2, -3])` should return `0` (no positive numbers to double and sum).


# Solution
```python test.py -r 'python test.py'
<prefix>

def process_numbers(input_list):
# Your code here
pass

</prefix>
<template>
<sol>
def process_numbers(input_list):
positive_numbers = [num for num in input_list if num >= 0]

doubled_values = [num * 2 for num in positive_numbers]

unique_values = set(doubled_values)

return sum(unique_values)
</sol>
</template>
<suffix>
if __name__ == "__main__":
input_list = list(map(int, input("Enter a list of integers separated by spaces: ").split()))
result = process_numbers(input_list)
print(result)
</suffix>
<suffix_invisible>

</suffix_invisible>

<prefix>

</prefix>
<template>
<sol> </sol>
</template>
<suffix>

</suffix>
<suffix_invisible>

</suffix_invisible>
```

# Public Test Cases
## Input 1

```
1, -3, 4, 2, -5, 2
```

## Output 1

```
14
```


## Input 2

```
1, 2, 3, -4, -5, 3
```

## Output 2

```
18
```


## Input 3

```
10, 10, -5, -5, 7
```

## Output 3

```
34
```


## Input 4

```
-1, -2, -3
```

## Output 4

```
0
```


# Private Test Cases

## Input 1

```
100, 50, -50, 100
```

## Output 1

```
300
```

## Input 2

```
5, -5, -5, 5
```

## Output 2

```
10
```
131 changes: 131 additions & 0 deletions data-types.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
---
title: Data Types Operations
tags: ['string', 'int','conversion','sum']
---

# Problem Statement
Write a function sum_first_last(input_str: str) -> int | str that takes a single string as input. The function should:

Check if the input string contains only numeric characters (0-9).
If the string contains only numbers, calculate the sum of the first and last digits and return the result.
If the string cannot be converted to an integer (contains any non-numeric characters), return the string "N/A".
Constraints:

The input string will be a non-empty string.
Length of string is more than or equal to 2.
Assume the string does not contain leading or trailing whitespace.
Do not use exception handling (try-except) for solving the problem.
Examples:

sum_first_last("12345") should return 6 (1 + 5).
sum_first_last("987654321") should return 10 (9 + 1).
sum_first_last("007") should return 7 (0 + 7).
sum_first_last("12a45") should return "N/A".
sum_first_last("abcd") should return "N/A".

# Solution
```python test.py -r 'python test.py'
<prefix>
def convert_and_sum(input_str: str) -> int | str:
# Your code here
pass
</prefix>
<template>
<sol>
def convert_and_sum(input_str: str) -> int | str:
if input_str.isdigit():
return sum(int(input_str[0])+int(input_str[-1]))
else:
return "N/A"
</sol>
</template>
<suffix>

if __name__ == "__main__":
input_str = input("Enter a string: ")
result = convert_and_sum(input_str)
print(result)
</suffix>
<suffix_invisible>
</suffix_invisible>

```
# Public Test Cases

## Input 1

```
12345
```

## Output 1

```
6
```


## Input 2

```
2098
```

## Output 2

```
10
```


## Input 3

```
1234a
```

## Output 3

```
N/A
```


## Input 4

```
a1234
```

## Output 4

```
N/A
```


# Private Test Cases

## Input 1

```
19
```

## Output 1

```
10
```

## Input 2

```
1a
```

## Output 2

```
N/A
```
Loading