Skip to content

Instantly share code, notes, and snippets.

View naemazam's full-sized avatar
🎯
Focusing

Naem Azam naemazam

🎯
Focusing
View GitHub Profile
''' 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
'''
@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]
@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.]]
'''
''' 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.
''' 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")
''' 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]]
'''
''' 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
'''
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
# A basic code for matrix input from user
R = int(input("Enter the number of rows:"))
C = int(input("Enter the number of columns:"))
# Initialize matrix
matrix = []
print("Enter the entries rowwise:")
# For user input
@naemazam
naemazam / bookmark.js
Created November 4, 2021 07:26 — forked from oilvier/bookmark.js
Javascript to add a bookmark - Cross Browser
/**
*
* Add to bookmark
* Several tests are necessary in order for this "simple" action to work in most of the browsers
*
*/
// First, we define the element where the "Add to bookmark" action will trigger
var triggerBookmark = $(".js-bookmark"); // It must be an `a` tag