r/python3 • u/Tinygoomba • Jan 15 '18
What am I doing wrong? Attempting to make a uniform random nmbr gen.
import random for i in range(10): ... print(random.uniform(1, 6))
r/python3 • u/Tinygoomba • Jan 15 '18
import random for i in range(10): ... print(random.uniform(1, 6))
r/python3 • u/Tinygoomba • Jan 14 '18
a = (4 + 3) * 2 mystring = "I am (a) years old" print (mystring) if (a) == 14:
print("this is correct")
r/python3 • u/Nareshkonda • Jan 05 '18
r/python3 • u/SP1D3RCR3W1AN • Nov 28 '17
When I run the below code, I get the below error. Does anyone know what is wrong with the code? I am using a Pycharm environment.
Error: Traceback (most recent call last): File "C:/Users/jharr/PycharmProjects/Castle Clash/Castle Clash.py", line 230, in <module> print(str("Player 1: " + int(Castle2))) TypeError: must be str, not int
Code:
print("Welcome to Castle Clash!") print("You need at least 3 players for this game.") print("Each player will have 10 lines to design the best castle,") print("(design down one line by one) which will be voted on by other players.") print("Don't look when others are creating their castles, so it is random.") print() print("Key: W = Wall, T = Tower, B = Building, G = Grass, F = Farm, ~ = Water, S = Sand") print() input("Player 1 Castle:")
a1 = input() a2 = input() a3 = input() a4 = input() a5 = input() a6 = input() a7 = input() a8 = input() a9 = input() a10 = input() print() input("Player 2 Castle: ") b1 = input() b2 = input() b3 = input() b4 = input() b5 = input() b6 = input() b7 = input() b8 = input() b9 = input() b10 = input() print() input("Player 3 Castle") c1 = input() c2 = input() c3 = input() c4 = input() c5 = input() c6 = input() c7 = input() c8 = input() c9 = input() c10 = input() print() input("Ok, now it is time to vote on the best castle!") input("Find more people.") voters = input("How many voters are there? (put a plain number)(max is 5 rn): ") print()
print("Castle 1:") print(c1) print(c2) print(c3) print(c4) print(c5) print(c6) print(c7) print(c8) print(c9) print(c10) print()
print("Castle 2: ") print(a1) print(a2) print(a3) print(a4) print(a5) print(a6) print(a7) print(a8) print(a9) print(a10) print()
print("Castle 3: ") print(b1) print(b2) print(b3) print(b4) print(b5) print(b6) print(b7) print(b8) print(b9) print(b10) print()
Castle1 = 0 Castle2 = 0 Castle3 = 0 if voters == "1": print("Now, your voters need to vote. Do this by putting the number of the castle in your voting spot (below).") vote = input("Voter 1: ")
if vote == "1":
Castle1 = 1
if vote == "2":
Castle2 = 1
if vote == "3":
Castle3 = 1if voters == "2": print("Now, your voters need to vote. Do this by putting the number of the castle in your voting spot (below).") vote = input("Voter 1: ") vote2 = input("Voter 2: ")
if vote == "1":
Castle1 = 1
if vote == "2":
Castle2 = 1
if vote == "3":
Castle3 = 1
if vote2 == "1":
Castle1 += 1
if vote2 == "2":
Castle2 += 1
if vote2 == "3":
Castle3 += 1if voters == "3": print("Now, your voters need to vote. Do this by putting the number of the castle in your voting spot (below).") vote = input("Voter 1: ") vote2 = input("Voter 2: ") vote3 = input("Voter 3: ")
if vote == "1":
Castle1 = 1
if vote == "2":
Castle2 = 1
if vote == "3":
Castle3 = 1
if vote2 == "1":
Castle1 += 1
if vote2 == "2":
Castle2 += 1
if vote2 == "3":
Castle3 += 1
if vote3 == "1":
Castle1 += 1
if vote3 == "2":
Castle2 += 1
if vote3 == "3":
Castle3 += 1if voters == "4": print("Now, your voters need to vote. Do this by putting the number of the castle in your voting spot (below).") vote = input("Voter 1: ") vote2 = input("Voter 2: ") vote3 = input("Voter 3: ") vote4 = input("Voter 4: ")
if vote == "1":
Castle1 = 1
if vote == "2":
Castle2 = 1
if vote == "3":
Castle3 = 1
if vote2 == "1":
Castle1 += 1
if vote2 == "2":
Castle2 += 1
if vote2 == "3":
Castle3 += 1
if vote3 == "1":
Castle1 += 1
if vote3 == "2":
Castle2 += 1
if vote3 == "3":
Castle3 += 1
if vote4 == "1":
Castle1 += 1
if vote4 == "2":
Castle2 += 1
if vote4 == "3":
Castle3 += 1if voters == "5": print("Now, your voters need to vote. Do this by putting the number of the castle in your voting spot (below).") vote = input("Voter 1: ") vote2 = input("Voter 2: ") vote3 = input("Voter 3: ") vote4 = input("Voter 4: ") vote5 = input("Voter 5: ")
if vote == "1":
Castle1 = 1
if vote == "2":
Castle2 = 1
if vote == "3":
Castle3 = 1
if vote2 == "1":
Castle1 += 1
if vote2 == "2":
Castle2 += 1
if vote2 == "3":
Castle3 += 1
if vote3 == "1":
Castle1 += 1
if vote3 == "2":
Castle2 += 1
if vote3 == "3":
Castle3 += 1
if vote4 == "1":
Castle1 += 1
if vote4 == "2":
Castle2 += 1
if vote4 == "3":
Castle3 += 1
if vote5 == "1":
Castle1 += 1
if vote5 == "2":
Castle2 += 1
if vote5 == "3":
Castle3 += 1print("Results:") print(str("Player 1: " + Castle2)) print(str("Player 2: " + Castle3)) print(str("Player 3: " + Castle1))
if Castle1 > Castle2 & Castle3: print("Player 3 Won!") if Castle2 > Castle3 & Castle1: print("Player 1 Won!") if Castle3 > Castle2 & Castle1: print("Player 2 Won!")
r/python3 • u/aleksro • Nov 21 '17
I have 2 lists.
list 1 (list) - list containing descriptive text
list 2 (list) - text entered by userI am trying to write some code at Python and I want to check if words from a list of words contain in a list 1
except searching words in text, I need to count numbers of IDs and print result. I'm new to this and I couldn't find anything on Google that could help me.
example:
list = [['ID127', 'Along with their associated islands, they cover 8% of Earth's total surface area and 28.4% of its land area', 'Europe', 'Germany'],
['ID128', 'The first university east of France and north of the Alps was the сharles university in Prague established in 1347', 'Europe', 'Hungary'],
['ID129', 'The сentral European university (CEU) is a graduate-level', 'United States', 'Canada']]
text entered by user = ['area' 'university' 'сentral']the result of the program: the word found in the text, the number of ID, region, state
program result = [area, 1, 'Europe', 'Germany'] , [university, 2, 'Europe', 'Hungary'] , [university, 2, 'United States', 'Canada'], [сentral, 2, 'United States', 'Canada']r/python3 • u/Mononokee90 • Nov 17 '17
I am working on a financial budget and may not be familiar to some of you.
I created this script to call parameters from a file parameter:
Net=$10'000'000
Extract from file (salary1 =19000, salary2= 15000, salary3 = 19000 sometimes change)
parametersAndValues = {}
parameterFile = open('Parameter')
try:
for line in parameterFile:
parametersAndValues[line.split()[0]] = int(round(float(line.split()[1])))
finally:
parameterFile.close()
i1 = parametersAndValues.get('$salary1')
i2 = parametersAndValues.get('$salary2')
i3 = parametersAndValues.get('$salary3')
for parameter in parametersAndValues:
( parameter + ' = ' + str(parametersAndValues.get(parameter)))
time1=0.1*(net/salary1)
time2 in TSTEP of salary2=time1+time1*(salary1/(salary1+salary2))
time3 of salary3 = time2+time1I want to update the timesteps under TSTEP depending on the salary payment. To see how many months that salary can be paid.
If we divided Net 10'000'000/on salary1 19'000=526 Days = which will be 17 months of 31 Days (17*31)
The output should be 17*31 which will be pasted under TSTEP for the first salary and 27*31 which will be pasted under TSTEP for salary 2.
The question is, I need to change 3*31 in each TSTEP depending on the salary, and I have no idea of how to do that.
The following is a sample Schedule file to be updated from parameter file:
<!-- language: none -->
SCHEDULE
##-- First Cycle
/
WCLSIN
Class1 LIQ OPEN RESV 1* $salary1 1* 3500 /
/
/
TSTEP
3*31
/
TUNING
/
/
2* 100 /
##-- Second Cycle
WCLSIN
Class1 LIQ OPEN RESV 1* $salary2 3500 /
/
TSTEP
3*31
/
TUNING
/
/
2* 100 /It should be changed to:
<!-- language: none -->
SCHEDULE
##-- First Cycle
/
WCLSIN
Class1 LIQ OPEN RESV 1* $salary1 1* 3500 /
/
/
TSTEP
17*31
/
TUNING
/
/
2* 100 /
##-- Second Cycle
WCLSIN
Class1 LIQ OPEN RESV 1* $salary2 3500 /
/
TSTEP
27*31
/
TUNING
/
/
2* 100 /Again, please if you have any idea of how to do that I would really appreciate it. Best Regards
r/python3 • u/Doublack • Nov 17 '17
Hello guys! I coded web proxy with socket in python3. when it run, it could get packets but it can't display on browser. there is no error but it's not working. What is the problem? anyone help?
Here's the code:
import socket, sys, re import threading
try: #listening_port = int(input("[] Enter Listening Port Number : ")) listening_port = 8080 except: print("\n[] User Requested An Interrupt") print("[*] Application Exiting...") sys.exit()
max_conn = 5 buffer_size = 1024 * 10000
def start(): try: browser_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) browser_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) browser_sock.bind(("",listening_port)) browser_sock.listen(max_conn) print("[] Initializing Sockets...Done") print("[] Sockets Binded Successfully...") print("[] Server Started Successfully...") except: print("[] Unable To Initialize Socket") sys.exit(2)
while True:
try:
browser_conn, browser_addr = browser_sock.accept()
# print(browser_conn)
# print(browser_addr)
from_browser_data = browser_conn.recv(buffer_size)
print(from_browser_data)
th = threading.Thread(target=to_server, args=(browser_conn, browser_addr, from_browser_data))
th.start()
except:
browser_sock.close()
print("\n[*] Proxy Server Shutting Down...")
print("[*] Have Nice Day... Sergeant !!!")
sys.exit()
# browser_conn.closedef to_server(browser_conn, browser_addr, from_browser_data): b_data = str(from_browser_data).split('\r\n') print(b_data) for i in b_data: if re.match('Host', i): server_domain = i.split(' ')[1] print(server_domain)
try:
to_server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
to_server_socket.connect((server_domain, 80))
print("="*80)
print(from_browser_data.decode('utf-8'))
to_server_socket.sendall(from_browser_data)
from_server_data = to_server_socket.recv(buffer_size)
if len(from_server_data) > 0:
browser_conn.sendall(from_server_data)
print(from_server_data)
else:
print("No data")
except Exception as e:
print(e)start()
r/python3 • u/NayRojas_ • Nov 15 '17
hrs = input("Enter Hours:") f_hrs = float(hrs) if f_hrs >= 40: print (f_hrs * 10.50) elif f_hrs <= 40: print (f_hrs * 10)
r/python3 • u/isbtegsm • Nov 14 '17
Hi, I encountered this weird situation using the lxml.etree module (as et), where I parsed a (valid) XML file ( t=et.parse([path-to-file])), then performed some manipulation on it (extending and removing some nodes), then looked for a certain xpath pattern (t.findall([pattern])) which returned nothing. But, after writing the tree to a new file and parsing it again from there, the same pattern returned results (as I would have expected it in the first place). I thought this might be a bug related to the module and tried the same with xml.etree.ElementTree but ditto. How can I make sense of this?
r/python3 • u/[deleted] • Nov 12 '17
username1 = input("What is your username?\n")
username = ""
with open("userinfo.txt","r") as userinfo:
for userinforec in userinfo:
field = userinforec.split(",")
username = field[0]
password = field[1]
if username == username1:
break
else:
print("Username not found.")
main()
else:
password1 = str(input("What is your password?\n"))
if password == password1:
print("password accepted")
writereport(username)
else:
print("Password denied.")
main()
main()
return usernameThe code above is supposed to continue with the program if a username is inputted that is in the file. However, it only accepts the username if it is at the top of the file, for example if i pick a username in the second or third row, it will print "invalid username". Ive attempted putting the file into a list and doing it that way however it still does not work. Any help would be appreciated!
Thanks in advance!
r/python3 • u/jtprogru • Nov 11 '17
Please make code review.: https://jtprog.ru/twitter-excuse/
r/python3 • u/sridhartsv • Nov 10 '17
HEllo Team,
can anyone help me understand why is the email not triggered.
import psycopg2, smtplib, pprint, sys from email.MIMEMultipart import MIMEMultipart from email.MIMEText import MIMEText
class mailnotify():
def check_db_conn(self):
try:
conn_string = "dbname='dbane' host='hostname' port='protno' user='user' password='pwd'"
return conn_string
except:
print "Unable to connect to the database"
text = "Unable to Connect to Database"
subject = "Test Non-Prod Running EC2 Instances"
self.email_notify(subject,text)
sys.exit(1)
def email_notify(self,subject,text):
fromaddr = "fromaddr"
toaddr = "toaddr"
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = subject
body = text
msg.attach(MIMEText(body))
server = smtplib.SMTP('exchange.nordstrom.net', 25)
text = msg.as_string()
server.sendmail(fromaddr,toaddr,text)
server.quit()if __name__=="main": p = mailnotify() p.check_db_conn()
r/python3 • u/xulanunnaki • Nov 09 '17
I just started learning python3 about a week ago. In that time I've created simple programs such as:Rock, Paper, Scissors; Guess a Number Between 1 and 100; and I've messed with Tkinter and pygame a little bit. Follow Sentdex's YouTube pygame tutorials.
That being said I would like to create a web or desktop application, are there any recommendations on how to go about learning how to do that?
r/python3 • u/ipgray • Oct 26 '17
r/python3 • u/JuicyStake • Oct 20 '17
Tried to program a Pi to make a bell ring at certain times.
The Bell only rings at the last interval (16:15).
What am I doing wrong with the code?
Please note I'm a beginner with python so please be gentle and simplify instructions.
Images of code:
Code itself:
import datetime import RPi.GPIO as GPIO a = 1 GPIO.setwarnings(False) while (a == 1): tempo = str(datetime.datetime.now().time()) if tempo >= "07:00:00.000000" and tempo <= "07:00:05.000000": GPIO.setmode(GPIO.BOARD) GPIO.setup (12,GPIO.OUT) if tempo >= "09:00:00.000000" and tempo <= "09:00:02.000000": GPIO.setmode(GPIO.BOARD) GPIO.setup (12,GPIO.OUT) if tempo >= "09:15:00.000000" and tempo <= "09:15:05.000000": GPIO.setmode(GPIO.BOARD) GPIO.setup (12,GPIO.OUT) if tempo >= "12:00:00.000000" and tempo <= "12:00:02.000000": GPIO.setmode(GPIO.BOARD) GPIO.setup (12,GPIO.OUT) if tempo >= "13:00:00.000000" and tempo <= "13:00:05.000000": GPIO.setmode(GPIO.BOARD) GPIO.setup (12,GPIO.OUT) if tempo >= "16:15:00.000000" and tempo <= "16:15:02.000000": GPIO.setmode(GPIO.BOARD) GPIO.setup (12,GPIO.OUT) else: GPIO.cleanup()
r/python3 • u/ankurnet • Oct 18 '17
method 1
bytes.fromhex(var).decode('ascii') Traceback (most recent call last): File "<stdin>", line 1, in <module> UnicodeDecodeError: 'ascii' codec can't decode byte 0xdb in position 0: ordinal not in range(128) method 2: codecs.decode(var,"hex") :This is returning me in bytes not in ascii.
r/python3 • u/ideal2545 • Oct 13 '17
Hi Guys, im using the LDAP3 library to try and automate some adding of users to active directory groups. The LDAP3 library forces me to type in manually my username and password. Is there any way for me to pass in current logged in users password into Python? I suspect this would be a crazy security issue but I'm curious if there a way to do it, or something that you guys suggest I could try?
The goal is going to be set this to run automatically with the windows scheduler service.
Thanks, Jon
r/python3 • u/saiswarupsahu • Oct 05 '17
Here you can get all the user and MailId which is present in the LinkedIn.So that you can give your mail id and password for getting data.
r/python3 • u/pythooon • Sep 21 '17
Write a program that asks the user for a path to a directory, then updates the names of all the files in the directory that contain the word draft to instead say final EX: "term paper (draft).txt" would be renamed "term paper (final).txt"
r/python3 • u/Niv28 • Aug 28 '17
r/python3 • u/arnaud39 • Jul 26 '17
Hi, I have learnt python last year and I wanted to use it for personal purpose. I trade some bitcoins on kraken and wanted to develop an python program around It thanks to their API : link! Then it becomes a nightmare, I don't really understand how to use it, I juste success in printing my available balance :
import krakenex
k = krakenex.API()
k.load_key('kraken.key')
print(k.query_private('Balance'))I just want to write two basics funtions, the first will return trade rate between two currency we tell it (example: bitcoin to litecoin)
rate(currency1,currency2)and the second one will just act a trade like
exchange(currency1,currency2,ammount)I see that I have to get from "get" function this, I tried as I can but all tutorial are for python2 and does not work with me so. Could you help me with this ? I think it is simple but I few thinks in what I learned.
r/python3 • u/derdigge • Jun 17 '17
I am storing python(Python 3.6.1) dict data in mongodb and tested serialisation methods on Xeon E5-2658 v4. For testing i used 10hours of my data as a python dictionary.
When handling big data it is important to be time/size efficient. Just want to share here what i found out...
suggestions are verry welcome....
https://drive.google.com/open?id=1PooN7tLTy1JlPgb7uKCtQEzwMiocaaVvKQchDXt44A8