Extracting Certain Numbers From an Int Value

## Extracting Certain Numbers From an Int Value

i am trying to get the numbers in individual form added to a list.

For example, if i input 3245, i want the list to say

```["3","2","4","5"]
```

I have tried using a for in statement but got back numbers ranging from 0 - 3244 which was expected.

Any insight would be greatly appreciated, i am very new to python and am trying to teach myself code and re-write all my projects for school that was done in c to turn them into python. NOTE: i am using python 3, not 2.

Here is the rest of my code if it helps.

```cc = []

card = int(input("Credit Card: "))

for n in range(card):
cc.append(n)
print(cc)
```

First of all, you should either accept the input number as string or convert it to string. That way, you can just parse through each character in the string and add them to the list. Currently you are getting the number 0-3244 because of you are looping for the amount of inputted number and adding the loop index to your list. Therefore, this should do what you want

```cc = []

card = input("Credit Card: ") # or str(int(input("Credit Card: ")))
# if you want to restrict it to integer

for n in range(len(card)): # loop by number of characters
cc.append(card[n]) # append each character
print(cc)
```

Sub ExtractNumbersFromCells() Dim objRange As Range, nCellLength As Integer, nNumberPosition As Integer, strTargetNumber As String ' Initialization strTargetNumber = "" ' Go through all the cells in the target range For Each objRange In Range("A2:A4") nCellLength = Len(objRange) ' Extract numbers from cells For nNumberPosition = 1 To nCellLength If IsNumeric(Mid(objRange, nNumberPosition, 1)) Then strTargetNumber = strTargetNumber & Mid(objRange, nNumberPosition, 1) End If Next

you can just convert the integer to string and iterate through every character of the string and during the iteration just append to cc.

```cc = []
card = int(input("Credit Card: "))
for i in str(card):
cc.append(i)
print(cc)
```

Method 2: Extract number only from text strings with VBA code. Here is a VBA code which also can do you a favor, please do as follows: 1. Hold down the Alt + F11 keys to open the Microsoft Visual Basic for Applications window. 2. Click Insert > Module, and paste the following code in the Module Window. VBA code: Extract number only from text

```a = 3245
b = list(str(a))
print(b)
```

The above code can convert an integer to a list of characters. First convert the integer to a string and then convert the string to a list form.

Here's one way: String digits = Integer.toString(num_1); int digit1 = Character.digit(digits.charAt(0), 10); int digit2 = Character.digit(digits.charAt(1), 10); int digit3 = Character.digit(digits.charAt(2), 10); Of course, if the integer has more than three digits, using a loop would be more practical:

I need to extract specific part (no of bits) of a short data type in C. . For Example I have a binary of 52504 as 11001101000 11000 and I want First 6 ( FROM LSB --> MSB i.e 011000 decimal 24) bits and rest of 10 bits ( 11001101000 decimal 820).

Bitwise AND your integer with the mask having exactly those bits set that you want to extract. Then shift the result right to reposition the extracted bits if desired. unsigned int lowest_17_bits = myuint32 & 0x1FFFF; unsigned int highest_17_bits = (myuint32 & (0x1FFFF << (32 - 17))) >> (32 - 17);

The number in both cases can be from 1 to 3 digits long with 1 further number after the decimal point. I have tried looking for the "Z" character and then extracting the 1 to 3 numbers between it and the decimal point and the same with the "L" character and then extracting the 1 to 3 numbers that follow it.