Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fc3640c

Browse files
Add files via upload
1 parent 68787ce commit fc3640c

File tree

2 files changed

+158
-0
lines changed

2 files changed

+158
-0
lines changed

‎Array Mathematics.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Basic mathematical functions operate element-wise on arrays. They are available both as operator overloads and as functions in the NumPy module.
2+
3+
# import numpy
4+
5+
# a = numpy.array([1,2,3,4], float)
6+
# b = numpy.array([5,6,7,8], float)
7+
8+
# print a + b #[ 6. 8. 10. 12.]
9+
# print numpy.add(a, b) #[ 6. 8. 10. 12.]
10+
11+
# print a - b #[-4. -4. -4. -4.]
12+
# print numpy.subtract(a, b) #[-4. -4. -4. -4.]
13+
14+
# print a * b #[ 5. 12. 21. 32.]
15+
# print numpy.multiply(a, b) #[ 5. 12. 21. 32.]
16+
17+
# print a / b #[ 0.2 0.33333333 0.42857143 0.5 ]
18+
# print numpy.divide(a, b) #[ 0.2 0.33333333 0.42857143 0.5 ]
19+
20+
# print a % b #[ 1. 2. 3. 4.]
21+
# print numpy.mod(a, b) #[ 1. 2. 3. 4.]
22+
23+
# print a**b #[ 1.00000000e+00 6.40000000e+01 2.18700000e+03 6.55360000e+04]
24+
# print numpy.power(a, b) #[ 1.00000000e+00 6.40000000e+01 2.18700000e+03 6.55360000e+04]
25+
# Task
26+
27+
# You are given two integer arrays, and of dimensions X.
28+
# Your task is to perform the following operations:
29+
30+
# Add ( + )
31+
# Subtract ( - )
32+
# Multiply ( * )
33+
# Integer Division ( / )
34+
# Mod ( % )
35+
# Power ( ** )
36+
# Input Format
37+
38+
# The first line contains two space separated integers, and .
39+
# The next lines contains space separated integers of array .
40+
# The following lines contains space separated integers of array .
41+
42+
# Output Format
43+
44+
# Print the result of each operation in the given order under Task.
45+
46+
# Sample Input
47+
48+
# 1 4
49+
# 1 2 3 4
50+
# 5 6 7 8
51+
# Sample Output
52+
53+
# [[ 6 8 10 12]]
54+
# [[-4 -4 -4 -4]]
55+
# [[ 5 12 21 32]]
56+
# [[0 0 0 0]]
57+
# [[1 2 3 4]]
58+
# [[ 1 64 2187 65536]]
59+
# Use // for division in Python 3.
60+
61+
62+
63+
64+
65+
66+
67+
68+
69+
import numpy
70+
71+
r = input().split()
72+
a = numpy.array([input().split()],int)
73+
b = numpy.array([input().split()],int)
74+
75+
print(numpy.add(a,b))
76+
print(numpy.subtract(a,b))
77+
print(numpy.multiply(a,b))
78+
print(a//b)
79+
print(numpy.mod(a,b))
80+
print(numpy.power(a,b))
81+

‎Find a string.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# In this challenge, the user enters a string and a substring. You have to print the number of times that the substring occurs in the given string. String traversal will take place from left to right, not from right to left.
2+
3+
# NOTE: String letters are case-sensitive.
4+
5+
# Input Format
6+
7+
# The first line of input contains the original string. The next line contains the substring.
8+
9+
# Constraints
10+
11+
12+
# Each character in the string is an ascii character.
13+
14+
# Output Format
15+
16+
# Output the integer number indicating the total number of occurrences of the substring in the original string.
17+
18+
# Sample Input
19+
20+
# ABCDCDC
21+
# CDC
22+
# Sample Output
23+
24+
# 2
25+
# Concept
26+
27+
# Some string processing examples, such as these, might be useful.
28+
# There are a couple of new concepts:
29+
# In Python, the length of a string is found by the function len(s), where is the string.
30+
# To traverse through the length of a string, use a for loop:
31+
32+
# for i in range(0, len(s)):
33+
# print (s[i])
34+
# A range function is used to loop over some length:
35+
36+
# range (0, 5)
37+
# Here, the range loops over to . is excluded.
38+
39+
40+
41+
42+
43+
44+
def count_substring(string, sub_string):
45+
length = len(sub_string)
46+
result = 0
47+
for i in range(0,len(string)):
48+
for j in range(i+length,len(string)):
49+
if string[i:j] == sub_string:
50+
result += 1
51+
return(result)
52+
53+
if __name__ == '__main__':
54+
string = input().strip()
55+
sub_string = input().strip()
56+
57+
count = count_substring(string, sub_string)
58+
print(count)
59+
60+
61+
62+
63+
64+
65+
# def count_substring(string, sub_string):
66+
# count=0
67+
# #print(len(string),len(sub_string))
68+
# for i in range(0, len(string)-len(sub_string)+1):
69+
# if string[i] == sub_string[0]:
70+
# flag=1
71+
# for j in range (0, len(sub_string)):
72+
# if string[i+j] != sub_string[j]:
73+
# flag=0
74+
# break
75+
# if flag==1:
76+
# count += 1
77+
# return count

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /