Skip to content

Commit 68ee489

Browse files
committed
soft update
1 parent 3f1535f commit 68ee489

File tree

29 files changed

+96
-92
lines changed

29 files changed

+96
-92
lines changed

binaryConvertor/binaryConvertor.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
bin_num = input("Enter binary number: ")
22
dec_num = 0
33

4-
# Using for loop
54
for i in range(len(bin_num)):
65
dec_num += int(bin_num[-(i+1)])*(2**i)
76

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
# user input
21
data = input("Enter the list of numbers separated by comma: ").split(',')
32

4-
# converting the list to integers
53
list_data = [int(i) for i in data]
64

7-
# sum of digits of each number
85
digit_sums = []
96
for num in list_data:
107
sum_of_digits = 0
@@ -13,6 +10,4 @@
1310
sum_of_digits += digit
1411
num //= 10
1512
digit_sums.append(sum_of_digits)
16-
17-
# printing the sum of digits
1813
print(digit_sums)

check_equal/check_equal.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
# function to check elements
21
def check_equal(list1):
32
return list1[1:] == list1[:-1]
43

5-
# lists
64
x = [10, 20, 30, 40, 50]
75
y = [10, 20, 20, 20, 20]
86
z = [10, 10, 10, 10, 10]
97

10-
# printing lists
118
print("x:", x)
129
print("y:", y)
1310
print("z:", z)
1411

15-
# checking elements
1612
print("check_equal(x):", check_equal(x))
1713
print("check_equal(y):", check_equal(y))
1814
print("check_equal(z):", check_equal(z))
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
## Summary
2+
The code snippet takes a list of integers as input from the user, converts it into a set, and then compares the length of the set with the length of the original list to determine if there are any duplicate elements in the list.
3+
4+
## Example Usage
5+
```python
6+
Enter the list elements: 1 2 3 4 5
7+
No, list does not contain duplicate element
8+
9+
Enter the list elements: 1 2 3 4 4
10+
Yes, list contains duplicate element
11+
```
12+
13+
## Code Analysis
14+
### Inputs
15+
- A list of integers entered by the user.
16+
___
17+
### Flow
18+
1. The code prompts the user to enter the list elements.
19+
2. The input is split into individual elements and converted into a list of integers using the `map()` function.
20+
3. The list is then converted into a set using the `set()` function.
21+
4. The code compares the length of the set with the length of the original list.
22+
5. If the lengths are equal, it means there are no duplicate elements in the list and the code prints "No, list does not contain duplicate element".
23+
6. If the lengths are not equal, it means there are duplicate elements in the list and the code prints "Yes, list contains duplicate element".
24+
___
25+
### Outputs
26+
- "No, list does not contain duplicate element" if there are no duplicate elements in the list.
27+
- "Yes, list contains duplicate element" if there are duplicate elements in the list.
28+
___

check_for_duplicates/check_for_duplicates.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
# Checking weather the list contains duplicate element or not
2-
3-
# taking input from the user
41
myList = list(map(int, input("Enter the list elements: ").split()))
52

6-
# Creating a set from the list
73
mySet = set(myList)
84

9-
# Checking the length of the set and list
105
if len(mySet) == len(myList):
116
print("No, list does not contain duplicate element")
127
else:

check_sublist_presence()./check_sublist_presence().py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
1-
# user input data
21
list_data = input("Enter the list of numbers separated by space: ")
32
list_data = list_data.split()
43
list_data = [int(i) for i in list_data]
54

6-
# user input sub list
75
sub_list = input("Enter the sub list of numbers separated by space: ")
86
sub_list = sub_list.split()
97
sub_list = [int(i) for i in sub_list]
108

11-
# variable to store the result
129
contains_sublist = False
1310

14-
# loop through the main list to find the sublist
1511
for i in range(len(list_data)-len(sub_list)+1):
1612
if list_data[i:i+len(sub_list)] == sub_list:
1713
contains_sublist = True
1814
break
1915

20-
# print the result
2116
if contains_sublist:
2217
print("YES")
2318
else:

check_unique_elements/check_unique_elements.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
# Taking input from the user for the number of elements
21
number_of_elements = int(input("Enter number of elements: "))
32
unique_elements_list = []
43

5-
# Appending elements to the list
64
for _ in range(number_of_elements):
75
element = int(input("Enter an element: "))
86
if element not in unique_elements_list:
97
unique_elements_list.append(element)
10-
11-
# Checking if all the elements are unique
8+
129
if len(unique_elements_list) == number_of_elements:
1310
print("All elements are unique")
1411
else:

count_number_types/count_number_types.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# Initialize counts for positive, negative, and zeros
21
positive_count = 0
32
negative_count = 0
43
zero_count = 0

count_strings_with_same_first_and_last_chars/count_strings_with_same_first_and_last_chars.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
# Enter a list of strings
21
strings = input("Enter strings separated by space: ").split()
3-
4-
# Count the number of strings with length 2 or more and first and last characters are the same
52
count = 0
63
for string in strings:
74
if len(string) >= 2 and string[0] == string[-1]:
Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
1-
# Prompt the user to enter elements separated by space
21
input_elements = input("Enter the list elements separated by space: ")
32

4-
# Convert the input string to a list of integers
53
elements_list = list(map(int, input_elements.split()))
64

7-
# Create a dictionary to store the count of each element
85
element_count = {}
96

10-
# Count the occurrences of each element in the list
117
for element in elements_list:
128
if element in element_count:
139
element_count[element] += 1
1410
else:
1511
element_count[element] = 1
1612

17-
# Print the occurrence count of each element
1813
for element, count in element_count.items():
1914
print(f"{element} occurs {count} {'time' if count == 1 else 'times'}")
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
## Summary
2+
The code snippet is a simple program that takes user input to create a list of elements, calculates the sum of all the elements in the list, and then prints the sum.
3+
4+
## Example Usage
5+
```python
6+
Enter number of elements: 4
7+
Enter an element: 2
8+
Enter an element: 5
9+
Enter an element: 1
10+
Enter an element: 3
11+
Sum of all elements: 11
12+
```
13+
14+
## Code Analysis
15+
### Inputs
16+
- The user is prompted to enter the number of elements they want to input.
17+
- The user is then prompted to enter each element one by one.
18+
___
19+
### Flow
20+
1. The code snippet prompts the user to enter the number of elements.
21+
2. It creates an empty list called `elements_list`.
22+
3. It uses a for loop to iterate `number_of_elements` times.
23+
4. Inside the loop, it prompts the user to enter an element and appends it to `elements_list`.
24+
5. It initializes a variable `total_sum` to 0.
25+
6. It uses another for loop to iterate over each item in `elements_list`.
26+
7. Inside the loop, it adds each item to `total_sum`.
27+
8. Finally, it prints the sum of all the elements in `elements_list`.
28+
___
29+
### Outputs
30+
- The code snippet prints the sum of all the elements in the list.
31+
___
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
# Taking input from the user for the number of elements
21
number_of_elements = int(input("Enter number of elements: "))
32
elements_list = []
43

5-
# Appending elements to the list
64
for _ in range(number_of_elements):
75
element = int(input("Enter an element: "))
86
elements_list.append(element)
9-
10-
# Calculating the sum of all elements
7+
118
total_sum = 0
129
for item in elements_list:
1310
total_sum += item
14-
15-
# Printing the sum
11+
1612
print("Sum of all elements:", total_sum)
Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
# Python program to print Fibonacci series
2-
3-
# take input from the user
41
n = int(input("How many terms? "))
52

6-
# first two terms
73
a = 0
84
b = 1
95

@@ -13,6 +9,5 @@
139
a, b = b, a + b
1410
count += 1
1511

16-
# end the program
1712
print()
1813

find_consecutive_numbers/find_consecutive_numbers.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
L = list(map(int, input("Enter the list of numbers separated by space: ").split()))
22
N = int(input("Enter the number of consecutive numbers: "))
33

4-
# list to store the numbers that are repeated N times consecutively
54
consecutive_numbers = []
65

7-
# loop through the list to find the consecutive numbers
86
for i in range(len(L)-N+1):
97
count = 1
108
for j in range(i+1, i+N):
@@ -14,7 +12,6 @@
1412
if count == N and L[i] not in consecutive_numbers:
1513
consecutive_numbers.append(L[i])
1614

17-
# print the result
1815
if consecutive_numbers:
1916
print("YES")
2017
print(consecutive_numbers)
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
L = input("Enter list of numbers separated by comma: ").split(",")
22
N = int(input("Enter Nth position from largest or smallest: "))
33

4-
# Converting string to int
54
L = [int(i) for i in L]
65

7-
# Finding Nth largest element
86
L.sort(reverse=True)
97
largest = L[N-1]
108
print(f"{N} largest is = {largest}")
119

12-
# Finding Nth smallest element
1310
L.sort()
1411
smallest = L[N-1]
1512
print(f"{N} smallest is={smallest}")

find_smallest_and_largest/find_smallest_and_largest.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
def find_smallest_and_largest(n):
2-
# Initialize variables to store the largest and smallest numbers
32
largest = float('-inf')
43
smallest = float('inf')
54

65
for _ in range(n):
76
num = int(input("Enter a number: "))
87

9-
# Check if the number is the largest or smallest so far
108
if num > largest:
119
largest = num
1210
if num < smallest:

getDifferentiator/getDifferentiator.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# program to enter numbers till the user wants and at the end display largest and smallest numbers entered
21
largest = None
32
smallest = None
43

input-output/input-output.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
# Get input from the user
21
user_input = input("Enter integers separated by spaces: ")
32

4-
# Split the input string into individual string integers
53
input_strings = user_input.split()
64

7-
# Convert string integers to integers and print each one
85
for string in input_strings:
96
try:
107
integer = int(string)

maxMin/maxMin.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ def maxMin(myList):
99
minimum = myList[i]
1010
return maximum, minimum
1111

12-
# Get user input
1312
list1 = input("Enter numbers separated by a space: ").split()
14-
# Convert each item to int type
1513
list1 = [int(item) for item in list1]
1614

1715
max1, min1 = maxMin(list1)

patterns/rectangle/rectangle.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
## Summary
2+
The code snippet is a loop that prints a pattern of asterisks.
3+
4+
## Example Usage
5+
```python
6+
for row in range(4):
7+
for column in range(10):
8+
print("* ", end="")
9+
print()
10+
```
11+
This code can be used to print a pattern of asterisks, with 4 rows and 10 columns. The output will be:
12+
```
13+
* * * * * * * * * *
14+
* * * * * * * * * *
15+
* * * * * * * * * *
16+
* * * * * * * * * *
17+
```
18+
19+
## Code Analysis
20+
### Inputs
21+
There are no inputs for this code snippet.
22+
___
23+
### Flow
24+
1. The code snippet uses a nested loop to iterate over the rows and columns.
25+
2. The outer loop iterates 4 times, representing the number of rows.
26+
3. The inner loop iterates 10 times, representing the number of columns.
27+
4. In each iteration of the inner loop, an asterisk followed by a space is printed.
28+
5. After printing all the asterisks in a row, a newline character is printed to move to the next row.
29+
___
30+
### Outputs
31+
The output of the code snippet is a pattern of asterisks with 4 rows and 10 columns. Each row consists of 10 asterisks separated by spaces.
32+
___

patterns/rectangle/rectangle.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
# Loop through each row
21
for row in range(4):
3-
# Loop through each column within the row
42
for column in range(10):
5-
print("* ", end="") # Output a star and a space
6-
print() # Move to the next line after printing all columns
3+
print("* ", end="")
4+
print()

quadratic_equation/quadratic_equation.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
import math
22

33
def find_roots(a, b, c):
4-
# Calculate the discriminant
54
discriminant = b**2 - 4*a*c
6-
7-
# Check if the discriminant is positive, negative, or zero
85
if discriminant > 0:
9-
# Two distinct real roots
106
root1 = (-b + math.sqrt(discriminant)) / (2*a)
117
root2 = (-b - math.sqrt(discriminant)) / (2*a)
128
return (root1, root2)
139
elif discriminant == 0:
14-
# One real root
1510
root = -b / (2*a)
1611
return (root,)
1712
else:
18-
# Complex roots
1913
real_part = -b / (2*a)
2014
imaginary_part = math.sqrt(-discriminant) / (2*a)
2115
return (real_part + imaginary_part * 1j, real_part - imaginary_part * 1j)

remove_duplicates/remove_duplicates.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
# removing all occurrences of an element from a Python list
2-
3-
# taking input from the user
41
L = input("Enter list of elements separated by comma: ").split(",")
52
x = int(input("Enter element to be removed: "))
63

7-
# converting string to int
84
L = [int(i) for i in L]
95

10-
# using list comprehension to remove all occurrences of x from L
116
result = [i for i in L if i != x]
127

138
print(result)

reverse_digits/reverse_digits.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
# Prompt the user to input an integer
21
num = int(input("Enter an integer: "))
3-
4-
# Initialize variables
52
reversed_num = 0
63

7-
# Reverse the digits of the input number
84
while num > 0:
95
digit = num % 10
106
reversed_num = (reversed_num * 10) + digit
117
num = num // 10
128

13-
# Output the reversed number
149
print("Reversed number:", reversed_num)

0 commit comments

Comments
 (0)