Skip to content

Commit 356d73c

Browse files
Code
1 parent eb009ac commit 356d73c

File tree

100 files changed

+1261
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+1261
-0
lines changed

32Bit_or_64Bit_Mode.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Write a Python Program to determine if the python shell is executing in 32bit or 64bit mode on operating system.
2+
import struct
3+
print(struct.calcsize('P') * 8)

Accept_Positive_&_Subtract_Number.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'''Write a Python program that accept a positive number and subtract from this number the sum of its digits
2+
and so on. Continues this operation until the number is positive.'''
3+
4+
def repeat_times(n):
5+
s = 0
6+
n_str = str(n)
7+
while (n > 0):
8+
n -= sum([int(i) for i in list(n_str)])
9+
n_str = list(str(n))
10+
s += 1
11+
return s
12+
print(repeat_times(9))
13+
print(repeat_times(21))

Accept_Two_Integers.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Write a python function to check whether a number is divisible by another number. accept two integers values from the user.
2+
def multiple(m, n):
3+
return True if m % n == 0 else False
4+
5+
print(multiple(20, 5))
6+
print(multiple(7, 2))

Accepts_Six_Numbers.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Write a Python Program that accepts six numbers as input and sorts them in descending Order.
2+
3+
'''Input: Input Consists of six numbers n1,n2,n3,n4,n5,n6 (-100000 ≤ n1,n2,n3,n4,n5,n6 ≤ 100000).
4+
The Six Numbers are Separated by a Space.'''
5+
6+
print("Input Six Integers: ")
7+
nums = list(map(int, input().split()))
8+
nums.sort()
9+
nums.reverse()
10+
print("After Sorting the said integers: ")
11+
print(*nums)

Actual_Module_Object.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Write a Python Program to Get the Actual Module Object for a Given Object.
2+
3+
from inspect import getmodule
4+
from math import sqrt
5+
print(getmodule(sqrt))
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Write a Python Program to add two positive integers without using '+' operator.
2+
# Note: Use bitwise operations to add two numbers.
3+
4+
def add_without_plus_operator(a, b):
5+
while b != 0:
6+
data = a & b
7+
a = a ^ b
8+
b = data << 1
9+
return a
10+
print(add_without_plus_operator(2, 10))
11+
print(add_without_plus_operator(-20, 10))
12+
print(add_without_plus_operator(-10, -20))

Anonymous_Function.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Write a Python Program to Get Numbers Divisible by Fifteen From a List Using an Anonymous Function.
2+
3+
from unittest import result
4+
5+
6+
num_list = [45, 55, 60, 37, 100, 105, 220]
7+
8+
# Use Anonymous Function to Filter
9+
result = list(filter(lambda x: (x % 15 == 0), num_list))
10+
print('Numbers Divisible by 15 are', result)

Calculate_Run_Time.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Write a python program to calculate the time runs (difference between start and current time) of a program.
2+
from timeit import default_timer
3+
def timer(n):
4+
start = default_timer()
5+
# some code here
6+
for row in range(0,n):
7+
print(row)
8+
print(default_timer() - start)
9+
10+
timer(5)
11+
timer(15)

Check_Installed_Python_Module.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Write a Python Program to get a list of locally installed python modules.
2+
3+
import pkg_resources
4+
installed_packages = pkg_resources.working_set
5+
installed_packages_list = sorted(["%s==%s" %(i.key, i.version)
6+
for i in installed_packages])
7+
8+
for m in installed_packages_list:
9+
print(m)

Check_Integer_64_Bits.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Write a Python Program to Check Whether an Integer Fits in 64 Bits.
2+
3+
int_val = 30
4+
if int_val.bit_length() <= 63:
5+
print((-2 ** 63).bit_length())
6+
print((2 ** 63).bit_length())

Check_Positive_Negative.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Write a Python Program to Check if a Number is Positive, Negative or Zero.
2+
3+
num = int(input("Enter the Number: "))
4+
if num > 0:
5+
print('It is Positive Number')
6+
7+
elif num == 0:
8+
print('It is Zero')
9+
10+
else:
11+
print('It is a Negative Number')

Check_three_given_lengths.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'''Write a Python program to check whether three given lengths(integers) of three sides from a right triangle.
2+
Print "Yes" if the given sides form a right triangle otherwise print "No".
3+
'''
4+
5+
# Input: Integers Separated by a single space. 1 ≤ lenght of the side ≤ 1,000
6+
print("Input three integers(sides of a triangle)")
7+
int_num = list(map(int, input().split()))
8+
x,y,z = sorted(int_num)
9+
10+
if x**2+y**2==z**2:
11+
print('Yes')
12+
else:
13+
print('No')

Combo_of_3_digit.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Write a Python program to create the combinatons of 3 digit combo.
2+
3+
nums = []
4+
for num in range(1000):
5+
num = str(num).zfill(3)
6+
print(num)
7+
nums.append(num)

Common_divisors_between_two_no.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Write a Python program to find common divisors between two numbers in a given pair.
2+
def ngcd(x, y):
3+
i = 1
4+
while(i<=x and i<=y):
5+
if(x%i==0 and y%i==0):
6+
gcd=i;
7+
i+=1
8+
return gcd;
9+
10+
def num_comm_div(x, y):
11+
n = ngcd(x, y)
12+
result = 0
13+
z = int(n**0.5)
14+
i = 1
15+
while(i <= z):
16+
if(n % i == 0):
17+
result += 2
18+
if(i == n/i):
19+
result-=1
20+
i+=1
21+
return result
22+
23+
print("Number of Common Divisors: ",num_comm_div(2, 4))
24+
print("Number of Common Divisors: ",num_comm_div(6, 12))
25+
print("Number of Common Divisors: ",num_comm_div(12, 24))

Compute_Product_List.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Write a Python Program to Compute the Product of a List of Integers (Without Using For Loop)
2+
3+
from functools import reduce
4+
nums = [10, 20, 30]
5+
6+
nums_product = reduce((lambda x, y: x * y), nums)
7+
print("Product of the Numbers:", nums_product)

Compute_digit_num_sum_two_integers.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Write a Python program to compute the digit number of sum of two given integers.
2+
'''
3+
Input: Each test case consists of two non-negative integers x and y which are separated by a space in a line.
4+
0 ≤ x,y ≤ 1000000
5+
'''
6+
print("Input Two Integers(A B): ")
7+
a,b = map(int, input().split(" "))
8+
print("Number of Digit of A and B: ")
9+
print(len(str(a+b)))

Contiguous_Subsequence.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'''Write a python program to find the maximum sum of a contiguous subsequence from a given sequence of numbers
2+
a1, a2, a3, ... An. A subsequence of one element is also a continuous subsequence.'''
3+
# Input: You Can Assume That 1 ≤ N ≤ 5000 and -100000 ≤ Ai ≤ 100000.
4+
# Input Numbers Are Separated by a Space. Input 0 to Exit.
5+
6+
while True:
7+
print("Input Number of Sequence of Numbers you want to input (0 to exit): ")
8+
n = int(input())
9+
if n == 0:
10+
break
11+
else:
12+
A = []
13+
Sum = []
14+
print("Input Number: ")
15+
for i in range(n):
16+
A.append(int(input()))
17+
Wa = 0
18+
for i in range(0,n):
19+
Wa += A[i]
20+
Sum.append(Wa)
21+
for i in range(0, n):
22+
for j in range(0, i):
23+
Num = Sum[i] - Sum[j]
24+
Sum.append(Num)
25+
print("Maximum Sum of the Said Contiguous Subsequence: ")
26+
print(max(Sum))

Convert_Int_to_Binary.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Write a python program to convert an integer to binary keep leading zeros.
2+
x = 12
3+
print(format(x, '08b'))
4+
print(format(x, '010b'))

Convert_String_to_List.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Write a Python Program to Print a long text, convert the string to a list and print all the words and their frequencies.
2+
3+
string_words = '''Bitcoin(₿) is the first decentralized digital currency created in January 2009. Bitcoin was
4+
created by Satoshi Nakamoto. The word bitcoin first originated from a white paper published on 31 October 2008.
5+
It is a compound of the words "bit" and "coin." Bitcoin uses peer-to-peer technology to operate with no central
6+
authority or banks. Managing transactions and the issuing of bitcoins is carried out collectively by the whole
7+
peer to peer network of bitcoin. Its implementation was released as open source for it can be seen and accessed
8+
by anyone.
9+
10+
Bitcoins are created as a reward for a process known as Bitcoin mining. Bitcoin is widely accepted for
11+
currencies, products, and services. Bitcoin has been censured for its use in illegal transactions,
12+
the large amount of electricity used by mining, a purely peer-to-peer version of electronic cash would allow
13+
online payments to be sent directly from one party to another without going through a central autority or
14+
financial institution.
15+
16+
Bitcoin mining is a highly complex computing process that uses complicated computer code to create a secure
17+
cryptographic system, as well as the process by which new bitcoin enters into circulation.
18+
mining is a record-keeping service done through the use of bitcoin mining rigs processing power.
19+
It involves very large, decentralized networks of computers connected through peer to peer technology
20+
throughout the world that verify and secure blockchains. Bitcoin mining takes over the Bitcoin database,
21+
which is called the blockchain.
22+
23+
Crypto miners compete to be the first one to verify Crypto transactions and earn rewards paid in
24+
Cryptocurrencies for their efforts. Crypto miners need to first invest in computer equipment that is
25+
specialized for mining (usually high-end GPUs among other powerful PC components), and typically require
26+
access to a low cost energy source.'''
27+
28+
words_list = string_words.split()
29+
30+
words_freq = [words_list.count(n) for n in words_list]
31+
32+
print("String:\n {} \n".format(string_words))
33+
print("List:\n {} \n".format(str(words_list)))
34+
print("Pairs (Words and Frequencies:\n {}".format(str(list(zip(words_list, words_freq)))))

Count_no_of_carry_operations.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Write a Python program to count the number of carry operations for each of a set of addition problems.
2+
def carry_no(x, y):
3+
ctr = 0
4+
if(x == 0 and y == 0):
5+
return 0
6+
z = 0
7+
for i in reversed(range(10)):
8+
z = x%10 + y%10 + z
9+
if z > 9:
10+
z = 1
11+
else:
12+
z = 0
13+
ctr += z
14+
x //= 10
15+
y //= 10
16+
17+
if ctr == 0:
18+
return "No Carry Operation."
19+
elif ctr == 1:
20+
return ctr
21+
else:
22+
return ctr
23+
24+
print(carry_no(786, 457))
25+
print(carry_no(5, 6))

Create_Bytearray_List.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Write a Python Program to Create a Bytearray from a List.
2+
print()
3+
nums = [10, 20, 56, 35, 17, 99]
4+
5+
# Create Bytearray from List of Integers.
6+
values = bytearray(nums)
7+
for x in values: print(x)
8+
print()

Create_Possible_Strings.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Write a python program to create all possible strings by using 'a','e','i','o','u'. Use the characters exactly once.
2+
import random
3+
char_list = ['a','e','i','o','u']
4+
random.shuffle(char_list)
5+
print(''.join(char_list))

Day_of_the_date.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'''Write a Python program to that reads a date (from 2016/1/1 to 2016/12/31) and prints the day of the date.
2+
Jan. 1, 2016, is Friday. Note that 2016 is a leap year.'''
3+
4+
# Input: Two integers m and d separated by a single space in a line, m ,d represent the month and the day.
5+
6+
from datetime import date
7+
print("Input Month and Date (Separated by a Single Space): ")
8+
m, d = map(int, input().split())
9+
weeks = {1:'Monday',2:'Tuesday',3:'Wednesday',4:'Thursday',5:'Friday',6:'Saturday',7:'Sunday'}
10+
w = date.isoweekday(date(2016, m, d))
11+
print("Name of the Date: ",weeks[w])

Debt_in_n_months.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'''
2+
Write a Python Program to compute the amount of the debt in n months. The borrowing amount is $100,000 and the
3+
loan adds 5% interest of the debt and rounds it to the nearest 1,000 above month by month.
4+
'''
5+
# Input: An integer n (0 ≤ n ≤ 100)
6+
7+
def round_n(n):
8+
if n%1000:
9+
return (1+n//1000)*1000
10+
else:
11+
return n
12+
13+
def compute_debt(n):
14+
if n==0: return 100000
15+
return int(round_n(compute_debt(n-1)*1.05))
16+
17+
print("Input Number of Months: ")
18+
result = compute_debt(int(input()))
19+
print("Amount of Debt: ","$"+str(result).strip())

Decimal_to_Hexadecimal.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Write a Python Program to Convert Decimal to Hexadecimal.
2+
3+
x = 30
4+
print(format(x, '02x'))
5+
x = 4
6+
print(format(x, '02x'))

Difference_distinct_pairs_array.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'''Write a Python program to compute the summation of the absolute difference of all distinct pairs in an
2+
given array (non-decreasing order).'''
3+
4+
def sum_distinct_pairs(arr):
5+
result = 0
6+
i = 0
7+
while i<len(arr):
8+
result += i*arr[i]-(len(arr)-i-1)*arr[i]
9+
i += 1
10+
return result
11+
print(sum_distinct_pairs([1,2,3]))
12+
print(sum_distinct_pairs([1,4,5]))

Difference_largest_&_smallest_int.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'''
2+
Write a Python program to find the difference between the largest integer and the smallest integer which
3+
are created by 8 numbers from 0 to 9. The number that can be rearranged shall start with 0 as in 00135668.
4+
'''
5+
# Input: Data is a sequence of 8 numbers (numbers from 0 to 9).
6+
# Output: The difference between the largest integer and the smallest integer.
7+
8+
print("Input an integer Created by 8 Numbers from 0 to 9: ")
9+
num = list(input())
10+
print("Difference Between the Largest and the Smallest Integer from the Given Integer: ")
11+
print(int("".join(sorted(num,reverse=True))) - int("".join(sorted(num))))

Directory_Wildcard.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Write a Python Program to Make File Lists From Current Directory Using a Wildcard.
2+
import glob
3+
file_list = glob.glob('*.*')
4+
print(file_list)

Divisors_num_given_even_or_odd.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Write a Python program to find the number of divisors of a given integer is even or odd.
2+
def divisors(n):
3+
for i in range(n):
4+
x = len([i for i in range (1,n+1) if not n % i])
5+
return x
6+
print(divisors(3))
7+
print(divisors(6))
8+
print(divisors(9))
9+
print(divisors(12))
10+
print(divisors(15))

Double_Quotes_Display_Strings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Write a Python Program to Use Double Quotes to Display Strings.
2+
import json
3+
print(json.dumps({'Sagar': 1, 'Mohit': 2, 'Goswami': 3}))

0 commit comments

Comments
 (0)