Skip to content

Instantly share code, notes, and snippets.

View naemazam's full-sized avatar
🎯
Focusing

Naem Azam naemazam

🎯
Focusing
View GitHub Profile
'''
example
Enter your value:5
[[1. 0. 0. 0. 0.]
[0. 2. 0. 0. 0.]
[0. 0. 3. 0. 0.]
[0. 0. 0. 4. 0.]
[0. 0. 0. 0. 5.]] '''
import numpy as np
''' Create a one-dimensional all 0 ndarray object with length n, and then make
the m-th element equal to 1
Enter n, m separated by spaces, and n > = m
[sample input]
10 5
[sample output]
[[0. 0. 0. 0. 1. 0. 0. 0. 0. 0.]]
'''
import numpy as np
''' Given a list b with a length of 12, output its shape. If its shape can be
changed to n * m, output the changed array, otherwise output NO.
[input form] integer n and m
[output form] if n * m = 12 is satisfied, the array is output, otherwise ”NO" is
output.
[sample input]
1 12
[sample output]
[[ 1 2 3 4 5 6 7 8 9 10 11 12]]
'''
''' Enter 3 integers and output the largest one.
[sample input]
1 2 3
[sample output]
3
'''
num1,num2,num3 = input("enter numbers ").split()
print(max(num1,num2,num3),"greatest")
''' Enter a non-zero integer from the keyboard, take the input of 0 as the
input end flag, calculate the average value, and count the number of
positive and negative numbers
[input form]
One line per integer. The last line is 0, indicating the end of
input.
[output form]
Output three lines.
The first line is the average. The second line is a positive number.
The third line is the number of negative numbers.
@naemazam
naemazam / 4 * 4 matrix diagonal of the array.
Created October 30, 2021 08:24
Create a 4 * 4 matrix with values of 1,2,3,4 on the main diagonal of the array
'''Create a 4 * 4 matrix with values of 1,2,3,4 on the main diagonal of the
array. The legend is as follows:
Input: 4
Output:
[[1. 0. 0. 0.]
[0. 2. 0. 0.]
[0. 0. 3. 0.]
[0. 0. 0. 4.]]
'''
@naemazam
naemazam / Try to write a recursive function
Last active November 13, 2022 08:42
write a recursive function. When the age (x) of the second person and total number (N) are input, the list of age composition of all people is output in reverse order
''' Suppose there are N people now, the first person is 3 years old, the second person is x years old
(unknown), and the age of the third person is the sum of the ages of the first two people, and so
on until the Nth person. Try to write a recursive function. When the age (x) of the second person
and total number (N) are input, the list of age composition of all people is output in reverse order.
Note: when the age of the M-th person is greater than 120, output ”Larger than 120!“ and the
reverse order list of the age of the first M-1 individuals.
[example input 1]
6,4
[sample output 1]
[15, 9, 6, 3]
''' Enter a string s and an integer n in the two lines respectively, and define a
function to move the string s to the right by n bits, and to the left when n is a
negative number. ‪‬‮‭‫
If s is an empty string ‘ ', output ‘ ' regardless of n.
[sample input]
For example, s ='123456 '
n=3
[sample output]
Output result: 456123
'''
''' There is a function f (x) defined on natural number, which is defined as
follows:
If x < 5, then f (x) = x;
If 5 < = x < 15, then f (x) = x + 6;
If x > = 15, then f (x) = x-6.
Try to write the function, enter the x value and return the corresponding f (x)
value.
[input form] the input line represents the natural number x.
[output form] the output line represents the calculation result f (x). If the
input data is illegal (e.g. negative integer), output "illegal input".
@naemazam
naemazam / remove the duplicate names and output a list containing non duplicate names.
Created October 20, 2021 10:12
Enter a series of English names separated by commas, including duplicate names. Please remove the duplicate names and output a list containing non duplicate names. The order of names is the same as that of input
def unique_list(text_str):
l = text_str.split()
temp = []
for x in l:
if x not in temp:
temp.append(x)
return ' '.join(temp)
text_str = input("enter names: ")
print("Original String:")