Python Articles

Page 812 of 855

Valid Sudoku in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 27-Apr-2020 5K+ Views

Suppose we have one 9x9 Sudoku board. We have to check whether that is valid or now. Only the filled cells need to be validated according to the following rules −Each row must contain the digits from 1-9 without repetition.Each column must contain the digits from 1-9 without repetition.Each of the 9 (3x3) sub-boxes of the grid must contain the digits from 1-9 without repetition.Suppose the Sudoku grid is like −537619598686348317266284195879This is valid.To solve this, we will follow these steps −for i in range 0 to 8create some empty dictionary called row, col and block, row_cube := 3 * (i ...

Read More

Bypass Anti-virus using Veil Framework

Ajay yadav
Ajay yadav
Updated on 20-Apr-2020 2K+ Views

This article is intended to demonstrate, how to bypass the anti-virus detection using the Veil framework, as it is a collection of tools designed for use during penetration testing. It currently consists of the following modules −Veil-Evasion − a tool to generate antivirus-evading payloads using a variety of techniques and languagesVeil-Catapult − a psexec-style payload delivery system that integrates Veil-EvasionVeil-PowerView − a powershell tool to gain network situational awareness on Windows domainsVeil-Pillage − a modular post-exploitation framework that integrates Veil-EvasionRequirementsTo install the Veil- Framework, you are supposed to configure the latest Python packages into your machine.How to InstallThe important point ...

Read More

Python: Cannot understand why the error - cannot concatenate 'str' and 'int' object ?

Jayashree
Jayashree
Updated on 13-Mar-2020 262 Views

This can be corrected by putting n+1 in brackets i.e. (n+1)for num in range(5):     print ("%d" % (num+1))Using %d casts the object following % to string. Since a string object can't be concatnated with a number (1 in this case) interpreter displays typeerror.

Read More

Python: Can not understand why I am getting the error: Can not concatenate 'int' and 'str' object

Ayush Gupta
Ayush Gupta
Updated on 12-Mar-2020 150 Views

This error is coming because the interpreter is replacing the %d with i and then trying to add 1 to a str, ie, adding a str and an int. In order to correct this, just surround the i+1 in parentheses. exampleprint("\ Num %d" % (i+1))

Read More

How can I eliminate numbers in a string in Python?

Arjun Thakur
Arjun Thakur
Updated on 05-Mar-2020 247 Views

You can create an array to keep track of all non digit characters in a string. Then finally join this array using "".join method. examplemy_str = 'qwerty123asdf32' non_digits = [] for c in my_str: if not c.isdigit(): non_digits.append(c) result = ''.join(non_digits) print(result)OutputThis will give the outputqwertyasdfexampleYou can also achieve this using a python list comprehension in a single line. my_str = 'qwerty123asdf32' result = ''.join([c for c in my_str if not c.isdigit()]) print(result)OutputThis will give the outputqwertyasdf

Read More

How to find keith numbers using Python?

Priya Pallavi
Priya Pallavi
Updated on 05-Mar-2020 861 Views

You can use the following code to find if a number is a keith number in python −Exampledef is_keith_number(n): # Find sum of digits by first getting an array of all digits then adding them c = str(n) a = list(map(int, c)) b = sum(a) # Now check if the number is a keith number # For example, 14 is a keith number because: # 1+4 = 5 # 4+5 = 9 # 5+9 = 14 while b < n: a = a[1:] + [b] b = sum(a) return (b == n) & (len(c) > 1) print(is_keith_number(14))OutputThis will give the output −True

Read More

How to add/subtract large numbers using Python?

karthikeya Boyini
karthikeya Boyini
Updated on 05-Mar-2020 2K+ Views

You can add/subtract large numbers in python directly without worrying about speed. Python supports a "bignum" integer type which can work with arbitrarily large numbers. In Python 2.5+, this type is called long and is separate from the int type, but the interpreter will automatically use whichever is more appropriate.As long as you have version 2.5 or better, just perform standard math operations and any number which exceeds the boundaries of 32-bit math will be automatically (and transparently) converted to a bignum.examplea = 182841384165841685416854134135 b = 135481653441354138548413384135 print(a - b)OutputThis will give the output −47359730724487546868440750000

Read More

How to find Kaprekar numbers within a given range using Python?

Nikitha N
Nikitha N
Updated on 05-Mar-2020 1K+ Views

A modified Kaprekar number is a positive whole number n with d digits, such that when we split its square into two pieces - a right hand piece r with d digits and a left hand piece l that contains the remaining d or d−1 digits, the sum of the pieces is equal to the original number (i.e. l + r = n).You can find Kaprekar numbers within a given range by testing each number for the given condition in the given range. exampledef print_Kaprekar_nums(start, end): for i in range(start, end + 1): ...

Read More

How to generate pyramid of numbers using Python?

Ankith Reddy
Ankith Reddy
Updated on 05-Mar-2020 968 Views

There are multiple variations of generating pyramids using numbers in Python. Let's look at the 2 simplest formsExamplefor i in range(5):    for j in range(i + 1):       print(j + 1, end="")    print("")OutputThis will give the output1 12 123 1234 12345ExampleYou can also print numbers continuously usingstart = 1 for i in range(5):    for j in range(i + 1):       print(start, end=" ")       start += 1 print("")OutputThis will give the output1 2 3 4 5 6 7 8 9 10 11 12 13 14 15ExampleYou can also print these numbers in reverse usingstart = 15 for i in range(5):    for j in range(i + 1):    print(start, end=" ")    start -= 1 print("")OutputThis will give the output15 14 13 12 11 10 9 8 7 6 5 4 3 2 1

Read More

How to handle very large numbers in Python?

Abhinanda Shri
Abhinanda Shri
Updated on 05-Mar-2020 13K+ Views

You can perform arithmetic operations on large numbers in python directly without worrying about speed. Python supports a "bignum" integer type which can work with arbitrarily large numbers. In Python 2.5+, this type is called long and is separate from the int type, but the interpreter will automatically use whichever is more appropriate.As long as you have version 2.5 or better, just perform standard math operations and any number which exceeds the boundaries of 32-bit math will be automatically (and transparently) converted to a bignum.examplea = 182841384165841685416854134135 b = 135481653441354138548413384135 print(a - b)OutputThis will give the output −47359730724487546868440750000

Read More
Showing 8111–8120 of 8,547 articles
« Prev 1 810 811 812 813 814 855 Next »
Advertisements