Python Daily
2.57K subscribers
1.48K photos
53 videos
2 files
38.9K links
Daily Python News
Question, Tips and Tricks, Best Practices on Python Programming Language
Find more reddit channels over at @r_channels
Download Telegram
move = input()
if move in ('1', '2', '3', '4', '5', '6', '7', '8', '9') and (int(move) not in (gamelist)):
plyr2list.append(int(move))
gamelist.append(int(move))
print (gamelist) #debug
position[int(move)-1] = ('O')
printboard()
movecount = movecount + 1
plyr2wintest()
elif move not in ('1', '2', '3', '4', '5', '6', '7', '8', '9'):
print ('That is not a valid move! Try again')
else: print ('That move is taken!, Try again')

#end game
if winner == True:
print ('Congrats!')
else: print ('Its a tie BOI!')
print (' ')

#playagain
answer = 0
valid = False
print ('Would you like to play again (y/n)')
while valid == False: #waits until valid answer is submitted
answer = input()
if answer == 'y':
print ('aight, resetting...')
valid = True
elif answer == 'n':
print ('aight, cya')
print (' ') #ASCII art up in here cause why not
print(' * ,MMM8&&&. *')
print(' MMMM88&&&&& .')
print(' MMMM88&&&&&&&')
print(' * MMM88&&&&&&&&')
print(' MMM88&&&&&&&&')
print(' MMM88&&&&&&')
print(' MMM8&&& *')
print(' |\___/| ')
print(' ) ( . ')
print(' =\ /=')
print(' )===( Thanks for playing *')
print(' / \ ')
print(' | |')
print(' / \ ')
print(' \ / ')
print(' _/\_/\_/\__ _/_/\_/\_/\_/\_/\_/\_/\_/\_/\_ ')
print(' | | | |( ( | | | | | | | | | | ')
print(' | | | | ) ) | | | | | | | | | | ')
print(' | | | |(_( | | | | | | | | | | ')
print(' | | | | | | | | | | | | | | | ')
print(' By Me yay| | | | | | | | | ')
valid = True
playgame = False
else: print ('answer not valid, please use y or n')
#End

**His code:**

#!/usr/bin/python
"""Noughts and Crosses."""

import sys

def Input(*args):
"""Kludge to handle python 2 and 3."""
if sys.version_info.major >= 3:
return input(*args)
return raw_input(*args)

bye = r"""
* ,MMM8&&&. *
MMMM88&&&&& .
MMMM88&&&&&&&
* MMM88&&&&&&&&
MMM88&&&&&&&&
MMM88&&&&&&
MMM8&&& *
|\___/|
) ( .
=\ /=
)===( Thanks for playing *
/ \
| |
/ \
\ /
_/\_/\_/\__ _/_/\_/\_/\_/\_/\_/\_/\_/\_/\_
| | | |( ( | | | | | | | | | |
| | | | ) ) | | | | | | | | | |
| | | |(_( | | | | | | | | | |
| | | | | | | | | | | | | | |
By Me yay | | | | | | | | |
"""


def Play():
"""Play one round of noughts and crosses."""
position = [' ' for _ in range(9)]

print ("What is player 1's name?")
name1 = Input()
print ("Thanks %s, What's player 2's name?" % name1)
name2 = Input()
print ('So %s is X and %s is O.' % (name1, name2))
Input('Press Enter to continue...')

PrintBoard(position)

players = [(name1, 'X'), (name2, 'O')]
Super Beginner Python question.

Hi all,

I am currently programming some descriptive analytics on a CSV file.

I have imported using Pandas as far as I know.

My general aim; Create a bar chart of Location occurrence within the CSV file

The image below is as far as I have got but this is not all of the variables.

I am wondering if there is a way of importing the 'many' different locations as separate variables as I need to add 1 to each variable when the regex is matched against the CSV.

The CSV column is called; \(Some are abbreviated for ease as variables\)

**Borough**

>COL = 0
>
>Barnet = 0
>
>Bexley = 0
>
>BAD = 0
>
>Brent = 0
>
>Bromley = 0
>
>Camden = 0
>
>Croydon = 0
>
>Ealing = 0
>
>Enfield = 0
>
>Greenwich = 0
>
>Hackney = 0
>
>HAF = 0
>
>Haringey = 0
>
>Harrow = 0
>
>Havering = 0
>
>Hillingdon = 0
>
>Hounslow = 0
>
>Islington = 0
>
>KAC = 0
>
>KUT = 0
>
>Lambeth = 0
>
>Lewisham = 0
>
>Merton = 0
>
>Newham = 0
>
>Redbridge = 0
>
>RUT = 0
>
>Southwark = 0
>
>Sutton = 0
>
>TowerHamlets = 0
>
>WalthamForest = 0
>
>Wandsworth = 0
>
>Westminster = 0
>
>OuterBorough = 0
>
>InnerBorough = 0

Here is my current code with the output of the image below:

#Start of Imports
import csv
import sys
import numpy as np
import pandas as pd
import re
import matplotlib.pyplot as plt
#End of Imports

#Start of Declarations
COL = 0
Barnet = 0
Bexley = 0
BAD = 0
Brent = 0
Bromley = 0
Camden = 0
Croydon = 0
Ealing = 0
#This is as far as I got when I thought something was wrong?
Enfield = 0
Greenwich = 0
Hackney = 0
HAF = 0
Haringey = 0
Harrow = 0
Havering = 0
Hillingdon = 0
Hounslow = 0
Islington = 0
KAC = 0
KUT = 0
Lambeth = 0
Lewisham = 0
Merton = 0
Newham = 0
Redbridge = 0
RUT = 0
Southwark = 0
Sutton = 0
TowerHamlets = 0
WalthamForest = 0
Wandsworth = 0
Westminster = 0
OuterBorough = 0
InnerBorough = 0
#End of Declarations

#Starts reading 'csv file'
csv = pd.read_csv ('land-area-population-density-london.csv') #Not sure what this does, index_col=3)

#Start of IF Statement
csva = np.array(csv)
for column in np.arange(0, csva.shape[0]):
if re.match(r"Barnet", str(csva[column][2])) is not None:
Barnet = Barnet + 1
elif re.match(r"Bexley", str(csva[column][2])) is not None:
Bexley = Bexley + 1
elif re.match(r"City of London", str(csva[column][2])) is not None:
COL = COL + 1
elif re.match(r"Barking and Dagenham", str(csva[column][2])) is not None:
BAD = BAD + 1
elif re.match(r"Brent", str(csva[column][2])) is not None:
Brent = Brent + 1
elif re.match(r"Bromley", str(csva[column][2])) is not None:
Bromley = Bromley + 1
elif re.match(r"Camden", str(csva[column][2])) is not None:
Camden = Camden + 1
elif re.match(r"Croydon", str(csva[column][2])) is not None:
Croydon = Croydon + 1
elif re.match(r"Ealing", str(csva[column][2])) is not None:
Ealing = Ealing + 1
#End of IF Statement

#Start of graph fields
#Below: Places is the labels for the placesvar
places = ('Barnet', 'Bexley', 'City of London', 'Barking and Dagenham', 'Brent', 'Bromley', 'Camden', 'Croydon', 'Ealing')
#Below: placesvar the actual 'places' pulled from CSV
placesvar = [Barnet, Bexley, COL, BAD, Brent, Bromley, Camden, Croydon, Ealing]
#Y Positioning numpy.arange (Again no idea what this does) length 'places pulled from csv'
y_pos = np.arange(len(placesvar))
#End of graph fields

#Start of Graph positions and Names
plt.bar(y_pos, placesvar, align='center')
plt.xticks(y_pos, places, rot
ation=60)
plt.ylabel('No. of occurance')
plt.xlabel('Locations')
plt.title('Occurance of Locations')
#plt.savefig('file.png')(Commented out for testing)
#End of Graph positions and Names
plt.show()



https://i.redd.it/n311chii2u111.png

/r/Python
https://redd.it/8oat6s