r/learningpython • • May 31 '19

Python Practice exercises for Text/Log processing

1 Upvotes

I am preparing for a timed coding tests for a devops related role…the questioins that would be asked will be in the format of:

  1. here is an excerpt of a log file

  2. here is the information (aggregation/summary etc) needed from the log file

  3. write the script that parses the log file to provide the summary needed.

I am looking for places online with questions of this format to practice. Unfortunately I have not found any. Any ideas where I can find such?


r/learningpython • • Mar 15 '19

what does self.accounts.values () mean?

1 Upvotes

r/learningpython • • Jan 24 '19

Noob help.

1 Upvotes

Could someone tell me why the second 'elif' option wouldn't print, instead of the 'else' option:

if 10 < 5 == True:

print('yes')

elif 10 < 5 == False:

print('needed')

elif 5 != 5:

print('bob')

else:

print('a;lskjdf;')

r/learningpython • • Jul 22 '18

Need help with using the 'TODO' feature of PyCharm.

1 Upvotes

Beginner Python user. I attached a screenshot. I have followed the tutorial as closely as possible on the Jetbrains website. I suspect that the example pictures in the tutorial show a different programming language so I suspect either the creation of the TODO items in my code need a different syntax or it is a feature of the pro-version. Any ideas. Thanks.


r/learningpython • • May 30 '18

Beginner stuck on an exercise.

1 Upvotes

Brute-forcing my way through the guide at introtopython.org. The beginner challenge. At the bottom of the page.

Make a list of ten aliens, each of which is one color: 'red', 'green', or 'blue'.

Red aliens are worth 5 points, green aliens are worth 10 points, and blue aliens are worth 20 points.

Use a for loop to determine the number of points a player would earn for destroying all of the aliens in your list.

It seems that the 'sum' command can't be put inside loops, the 'print' command or functions.

aliens['rALien', 'gAlien', 'bAlien', 'gAlien', 'bAlien', 'rAlien', 'rAlien', 'gAlien', 'bAlien', 'bAlien']

current_points = '0'

def t(g):
for f in g:
	if f == 'rAlien':
		current_points.append(5)
	elif f == 'gAlien':
		current_points.append(10)
	else:
		current_points.append(20)
n = sum(g)
print('You get %s points for destroying all of the aliens in this stage.'%n)

I always get an error. "TypeError: unsupported operand type(s) for +: 'int' and 'str'" for the 'sum' line. Thanks guys. I'm having a rough go at learning python alone from zero.


r/learningpython • • May 15 '18

Ping command in Python

1 Upvotes

Hello guys, I am trying to run a python script to ping an IP:

import subprocess as sp ip = "10.198.195.169" status, result = sp.getstatusoutput("ping -c1 -w2" + ip) if(status ==0): print("UP") else: print("DOWN")

note: the IP is a valid server which is connected to the network. The answer is always "DOWN" Could you please assist me?


r/learningpython • • Jan 25 '18

Trying to figure out writing to specific columns in a csv

Thumbnail
stackoverflow.com
1 Upvotes

r/learningpython • • Dec 16 '17

I'm trying to strip working code and get invalid literal for int

1 Upvotes

https://gist.github.com/misiekofski/2e7138d936aa6fbf5ad483e529bb2b7e So first code (non-stripped) works properly with text file (tsp.txt) where I put in first line: no of cities, then in next lines x,y coordinates for this cities.

Then I try to strip this code from timeit.timeit (setup, code...) as you see in stipped.py and i get error:

Traceback (most recent call last):
  File "./stripped.py", line 25, in <module>
    closest, dist = closestpoint(path[-1], route)
  File "./stripped.py", line 15, in closestpoint
    d = math.sqrt((int(point[0]) - int(p[0]))**2 + (int(point[1]) - int(p[1]))**2)
ValueError: invalid literal for int() with base 10: '['

Anyone can tell me how to fix it? And why is this happening (less important?)


r/learningpython • • Dec 13 '17

Problems in making Monte Carlo Simulation

1 Upvotes

algorithm

import numpy as np
import scipy.stats as stats
vector = [] 
    for j in range(0,10):    
        for i in range(0,1000000):
            x = np.random.random_sample(100)
            mean = np.mean(x)
            vector.append(mean)
    jarque_bera = stats.normaltest(vector)
    print(jarque_bera)

The problem

According to the Central limit theorem :" suppose that a sample is obtained containing a large number of observations, each observation being randomly generated in a way that does not depend on the values of the other observations, and that the arithmetic average of the observed values is computed. If this procedure is performed many times, the central limit theorem says that the computed values of the average will be distributed according to a normal distribution". Why does the Jarque Bera test keep to reject the hypothesis of normal distribution for vector ?

results

NormaltestResult(statistic=10.36914457050475, pvalue=0.0056023323030836127)
NormaltestResult(statistic=16.105673081326248, pvalue=0.00031819805943059034)
NormaltestResult(statistic=25.155970060993226, pvalue=3.4470732148263561e-06)
NormaltestResult(statistic=23.504195723985241, pvalue=7.8727914609218084e-06)
NormaltestResult(statistic=27.922370302011636, pvalue=8.6443895187212056e-07)
NormaltestResult(statistic=40.003041798355852, pvalue=2.0580211982431137e-09)
NormaltestResult(statistic=50.44644948086755, pvalue=1.1109453088640159e-11)
NormaltestResult(statistic=52.06940786077795, pvalue=4.9348248730555328e-12)
NormaltestResult(statistic=62.289462476069879, pvalue=2.978619874512897e-14)
NormaltestResult(statistic=68.115353210065834, pvalue=1.6178527221720581e-15)

r/learningpython • • Oct 27 '17

(i'm a noob) so i'm making a simple text based game using pycharm and its not working, can anybody help me?

1 Upvotes

so i have the code like this:

a1 = sys.stdin.readline()

if a1 is 'yes': print('ok') else: print('goodbye') and its just printing goodbye no matter what i do, HHHEEEEEELLLLPPPP!!!!!!!


r/learningpython • • Oct 11 '17

Implementing beanstalk to create a scaleable web scraper

Thumbnail
blog.adnansiddiqi.me
1 Upvotes

r/learningpython • • May 13 '17

url.replace("learning", "learn")

Thumbnail
reddit.com
1 Upvotes