Jump to content

Help with finding integer within .txt file line

AMD Lover

I can't figure this out at all.....

Capture.JPG

Work Desktop | CPU: Intel Core i7 4770k | GPU: Quadro K1200 | Motherboard: EVGA Z97 Classified | RAM: Corsair Dominator Platinum 32GB (4x8GB) DDR3-2133Mhz | PSU: Seasonic 750W SS-750KM3 80 PLUS Gold | STORAGE: WD 1TB Se Enterprise Grade Drive & Corsair Neutron NX500 400GB NVMe PCIe  | COOLER: Enermax Liqtech 240 -  5x Noctua NF-F12 iPPC 2000 PWM | CASE: Corsair 600C | OS: Windows 10 Pro | Peripherals: Logitech MX Master 2S -- Logitech K840 -- INTEL X520 10Gb NIC -- 3x Acer H236HL -- Build Log | 

 

Work Server | CPU: Intel Xeon E5-2650 v3 | Model: Cisco UCS C220 M4 (SFF) | RAM: 64GB (4x16GB) Cisco (Samsung) DDR4 2133Mhz | STORAGE: 4x Cisco (Seagate) 900GB 10K 2.5" (RAID 10) - 2x 32GB Cisco FlexFlash Boot Drive (RAID 1) | OS: vSphere 6.7 Enterprise Plus U3 | 

 

Laptop | CPU: Intel Core i7 6700HQ | GPU: Nvidia GTX 960M 2GB GDDR5 | RAM: 32GB (2 x 16GB) DDR4-2400Mhz | STORAGE: 512GB Hynix NVMe | OS: Windows 10 Pro |

 

Gaming Desktop | CPU: Intel Core i7 9700K | GPU: Gigabyte RTX 2080 WINDFORCE 8G  | Motherboard: ASRock Z390 PHANTOM GAMING-ITX | RAM: Ballistix Elite 32GB Kit (16GB x 2) DDR4-3000 | PSU: Silverstone SX700-LPT 700w 80 PLUS Platinum | STORAGE: 2x Samsung 970 PRO 1TB NVMe | COOLER: Noctua NH-L12 | CASE: Louqe Ghost S1 | OS: Windows 10 Pro | Build Log in Progress | 

 

Home Server | CPU: Intel Xeon E5-2690 (Sandy Bridge) | GPU: Quadro P2000 | Motherboard: SUPERMICRO X9SRL-F  | RAM: 64GB (8x8GB) Micron VLP DDR3-1600 ECC | PSU: SUPERMICRO 665W 80 PLUS Bronze | STORAGE: 2x Samsung 860 EVO 500GB (RAID 1) - 4x WD 8TB Ultrastar (RAID 10) - Intel SSD D3-S4510 Series 240GB (BOOT)  | COOLER: Noctua NH-U12DXi4 with 2x Noctua NF-F12 iPPC 3000 PWM | CASE: SUPERMICRO CSE-842TQ-665B 4U | OS: vSphere 6.7 Enterprise Plus U3 | Build Log in Progress |

 

| Pixel 4XL 128GB - Clearly White - Unlocked - Carrier: Visible |

 

| F@H STATS |

Link to comment
Share on other sites

Link to post
Share on other sites

just use a regular expression

i want to die

Link to comment
Share on other sites

Link to post
Share on other sites

This seems like a homework problem so I'll avoid giving you the answer straight off the bat.

 

A hint: Why not split your string on whitespace?

input_file.readLine.split()

will do this for you. It returns a list for you to iterate over :)

"The only person you are destined to become is the person you decide to be."


CPU: Intel i5 4690K - Motherboard: Asus Maximus VII Ranger - RAM: Corsair Vengeance LP - 2x4GB @ 1866Mhz - GPU: MSI Twin Frozr GTX 770 4GB - CPU Cooler: Be Quiet! Dark Rock Pro 3 CPU Cooler - PSU: EVGA SuperNova G2 750W - Storage: Seagate Barracuda 2TB HDD- Case: Fractal Design Define R4 Windowed (with Red AKASA Led Strips) - Display: Benq GL2460HM 24" Monitor

Link to comment
Share on other sites

Link to post
Share on other sites

On 4/5/2016 at 11:50 PM, Tazman192 said:

This seems like a homework problem so I'll avoid giving you the answer straight off the bat.

 

A hint: Why not split your string on whitespace?


input_file.readLine.split()

will do this for you. It returns a list for you to iterate over :)

Anymore help you can give me? I have more stuff I need help on I don't understand as well.

Work Desktop | CPU: Intel Core i7 4770k | GPU: Quadro K1200 | Motherboard: EVGA Z97 Classified | RAM: Corsair Dominator Platinum 32GB (4x8GB) DDR3-2133Mhz | PSU: Seasonic 750W SS-750KM3 80 PLUS Gold | STORAGE: WD 1TB Se Enterprise Grade Drive & Corsair Neutron NX500 400GB NVMe PCIe  | COOLER: Enermax Liqtech 240 -  5x Noctua NF-F12 iPPC 2000 PWM | CASE: Corsair 600C | OS: Windows 10 Pro | Peripherals: Logitech MX Master 2S -- Logitech K840 -- INTEL X520 10Gb NIC -- 3x Acer H236HL -- Build Log | 

 

Work Server | CPU: Intel Xeon E5-2650 v3 | Model: Cisco UCS C220 M4 (SFF) | RAM: 64GB (4x16GB) Cisco (Samsung) DDR4 2133Mhz | STORAGE: 4x Cisco (Seagate) 900GB 10K 2.5" (RAID 10) - 2x 32GB Cisco FlexFlash Boot Drive (RAID 1) | OS: vSphere 6.7 Enterprise Plus U3 | 

 

Laptop | CPU: Intel Core i7 6700HQ | GPU: Nvidia GTX 960M 2GB GDDR5 | RAM: 32GB (2 x 16GB) DDR4-2400Mhz | STORAGE: 512GB Hynix NVMe | OS: Windows 10 Pro |

 

Gaming Desktop | CPU: Intel Core i7 9700K | GPU: Gigabyte RTX 2080 WINDFORCE 8G  | Motherboard: ASRock Z390 PHANTOM GAMING-ITX | RAM: Ballistix Elite 32GB Kit (16GB x 2) DDR4-3000 | PSU: Silverstone SX700-LPT 700w 80 PLUS Platinum | STORAGE: 2x Samsung 970 PRO 1TB NVMe | COOLER: Noctua NH-L12 | CASE: Louqe Ghost S1 | OS: Windows 10 Pro | Build Log in Progress | 

 

Home Server | CPU: Intel Xeon E5-2690 (Sandy Bridge) | GPU: Quadro P2000 | Motherboard: SUPERMICRO X9SRL-F  | RAM: 64GB (8x8GB) Micron VLP DDR3-1600 ECC | PSU: SUPERMICRO 665W 80 PLUS Bronze | STORAGE: 2x Samsung 860 EVO 500GB (RAID 1) - 4x WD 8TB Ultrastar (RAID 10) - Intel SSD D3-S4510 Series 240GB (BOOT)  | COOLER: Noctua NH-U12DXi4 with 2x Noctua NF-F12 iPPC 3000 PWM | CASE: SUPERMICRO CSE-842TQ-665B 4U | OS: vSphere 6.7 Enterprise Plus U3 | Build Log in Progress |

 

| Pixel 4XL 128GB - Clearly White - Unlocked - Carrier: Visible |

 

| F@H STATS |

Link to comment
Share on other sites

Link to post
Share on other sites

10 hours ago, AMD Lover said:

Anymore help you can give me? I have more stuff I need help on I don't understand as well.

Okay.

 

So let's say I do:

 

splitStrings = input_file.readLine.split()

 

Assume your .txt file has the line "I am 20 years old".

 

Once you load the file in (I assume you are doing this correctly, print() is your best friend for testing),

 

 

Then

splitStrings = ["I", "am, "20",  "years", "old"]

Now, what the split function does is, if no parameters are passed in (like in our case), then the delimiter (the character to split words on) is simply whitespace (space, tab, newline). So using split with no parameters is a neat way to split up a line into a bunch separate words. We now have our array of separate words, time to check if any of the "words" are in fact a digit.

 

 

We have a digit in the 2nd index (counts start from 0). We as the programmer know this, how can we get python to acknowledge this? Iterate through the array splitStrings.

 

How do we iterate through the array?

 

for x in splitStrings:
	do something

 

What this will do is it will loop through every element in splitStrings, starting from "I", and assign it to a variable x. What do you want to do with x? You want to check if it's a digit, if so, print it, and move on to the next word in the array. If it's not, skip it, and move on to the next word in the array.

 

Now all you need to figure out how to check if x is a digit. Hint: The exact function you need is in your code :)

 

Once again, print() is your best friend. This isn't a big program, but it could be challenging for someone new to programming. Why not split up the tasks? First ensure you're loading the file properly using print statements. Then use the for loop above but replace

 

do something

 

with

 

print(x)

to ensure you're loading and looping properly.

 

 

Let me know how you get on :)

"The only person you are destined to become is the person you decide to be."


CPU: Intel i5 4690K - Motherboard: Asus Maximus VII Ranger - RAM: Corsair Vengeance LP - 2x4GB @ 1866Mhz - GPU: MSI Twin Frozr GTX 770 4GB - CPU Cooler: Be Quiet! Dark Rock Pro 3 CPU Cooler - PSU: EVGA SuperNova G2 750W - Storage: Seagate Barracuda 2TB HDD- Case: Fractal Design Define R4 Windowed (with Red AKASA Led Strips) - Display: Benq GL2460HM 24" Monitor

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×