Skip to content

Instantly share code, notes, and snippets.

View naemazam's full-sized avatar
🎯
Focusing

Naem Azam naemazam

🎯
Focusing
View GitHub Profile
@naemazam
naemazam / Read in an integer n and output the first n lines of Yang Hui triangle
Last active October 16, 2021 18:43
Yang Hui triangle is also look like Pascal triangle
def fact(n):
azam=1
for c in range(1,n+1):
azam = azam*c
return azam
rows = int(input("Enter how many row you want to see :\n "))
for i in range(0, rows):
for j in range(1, rows-i):
print(" ", end="")
@naemazam
naemazam / Write a program to receive strings and print letters in descending order of character occurrence frequency
Created October 16, 2021 17:58
Write a python program a program to print letters in descending order of character occurrence frequency like example "google" output should be g-2 ,0 -2 , l- 1, b-1
love= input('enter a string ')
def rev(string):
d = dict()
for key in string:
if key not in d:
d[key] = 1
else:
d[key] += 1
return d
@naemazam
naemazam / Duplicate element determination
Last active October 20, 2021 08:17
Write a function that accepts the list as a parameter. If an element appears in the list more than once, it returns true, but do not change the value of the original list. At the same time, write a program that calls this function and test results.
def common_data(list1, list2):
result = False
for x in list1:
for y in list2:
if x == y:
result = True
return result
#azam
print("Enter elements of a list separated by space")
input_string1 = input('Enter Main list \n')
@naemazam
naemazam / removing duplicate characters
Created October 20, 2021 09:27
Enter a non empty string. After removing duplicate characters, sort from small to large and output it as a new string.
user_input = input("Enter a string:")
new_string = sorted(set(user_input))
new_data = "".join(new_string)
print(new_data)
@naemazam
naemazam / Enter a positive integer n between 1 and 100, and randomly generate a positive integer m not greater than n with n as the random number seed
Created October 20, 2021 09:30
Enter a positive integer n between 1 and 100, and randomly generate a positive integer m not greater than n with n as the random number seed. Generate a list ls containing elements 1, 2, 3... n, delete the elements with the integer multiple of m in the list ls, and output the original list and the list after deleting the multiple of m in two lines.
import random
n=int(input("Enter n value: "))
random.seed(n)
m=random.randint(1,n)
print(m)
lis=[i for i in range(1,n+1)]
print(lis)
up_lis=[i for i in lis if i%m!=0]
print(up_lis)
''' When logging in the system, the user needs to first enter the account. If the account does not exist, output ”Wrong User"
and end the program; When the account number is correct, enter the password again to verify whether the account password is
consistent with the given account password. If it is consistent, output ”Success", otherwise output ”Fail" and the
remaining attempts. The total number of attempts is 3. If all three attempts are input incorrectly, ”Login Denied" is output.'''
dic={"aaa" : ["123456",10000],"bbb" : ["888888",5000],"ccc" : ["333333",3000]}
user_name=input("Enter User Name: ")
if user_name in dic.keys():
for i in range(3):
pas=input("Enter Password: ")
@naemazam
naemazam / output a list of all prime numbers
Created October 20, 2021 09:57
input a natural number greater than 2, and then output a list of all prime numbers less than that number
n=int(input("Enter natural number greater then 2: "))
primes = []
for i in range (2, n):
for j in range(2, i):
if i%j == 0:
break
else:
primes.append(i)
print(primes)
@naemazam
naemazam / Input characters and sort the output according to the ASCII code value from small to large
Created October 20, 2021 10:08
Input three characters from the keyboard and sort the output according to the ASCII code value from small to large, with a space between the characters.
str1 = input("Enter Character: ")
result = ' '.join(sorted(str1))
print(result, end=" ")
@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:")
''' 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".