r/pythonhelp • • May 26 '20

I need help. I get 4 numbers from one to six and I want to take out the lowest and add the rest but for some reason it doesn't print if the numbers are lowest in C or D.

Post image
2 Upvotes

r/pythonhelp • • May 18 '20

Hopefully a simple solve

2 Upvotes

Hi all -- I'm a masters student in NYC and am taking a very rudimentary software design class. As part of our final, we are supposed to create a very simple MVP to write documentation on. I'm running into some issues with my Python code and hope you may be of some help!

Basically, I am trying to create a program that compares and input variable against a list/set/dictionary of words. I hope to make it more complex, but as of now -- I am just asking that the user pop in a string and then the program will spit out whether the string exists in the list/set/dictionary.

Without providing my lists (they are huge), here's what the code looks like:

leveler = input("Please choose grade: K or G1 >> ")
if leveler == 'K' : 
input("Please input word for Kindergarten leveling: ")
elif leveler == 'G1' :
input("Please input word for Grade 1 leveling: ")
kindergarten_list = ['a', 'b', 'c']
grade1_list = ['x', 'y', 'z']
kindergarten_set = set(kindergarten_list)
grade1_set = set(grade1_list + kindergarten_list)
if leveler in kindergarten_set :
print ('True')
if leveler not in kindergarten_set :
print ('False')

No matter what I enter, I get a "False." Any idea why?

Also, I am hoping to make this program more complex as long as it isn't a huge lift. Instead of entering words against the lists/sets, I want to enter a sentence. Then I want the program to spit out whatever words are NOT part of the given list/set.

Thanks in advance for any help!


r/pythonhelp • • May 17 '20

Need some assistance....

2 Upvotes

I have a handful of exercises to complete, and to the pint not finding much online.. here is one, help greatly appreciated.,

Define and test a function named posterize. This function expects an image and a tuple of RGB values as arguments. The function modifies the image like the blackAndWhite function, but it uses the given RGB values instead of black.


r/pythonhelp • • May 15 '20

Pickling floating point numbers with Tkinter GUI. Please help!

2 Upvotes

Hi Guys, hope you are all healthy and busy on your python projects during this crisis.

I'm programming my first GUI in Tkinter and I have a small program which takes various user input of pipe sizes/ materials etc (through entry widgets) and outputs weights and fluid weights etc.

I'm a real beginner who learns by banging rocks (or code) together so please don't laugh too much! my code is pretty messy.

I'm just working on the Save / load module now and I'm having some problems getting the pickle module to work with float numbers. My GUI has an output area where results are displayed - these are shown by labels and the get() method to show the results to 2 decimal places by using 'round'.

I want to add persistence to my program and I have used Pickle to get all of these pre-existing entry boxe and result label variables and output them to a .spool file (or could be a .dat) and then load them back in as the user desires. This basically works perfectly apart from the results always come back in as integer numbers and not floats, so basically the result labels lose accuracy in this way. I can't understand why the labels in my results frame are 'getting' the variables and showing them as floats, but the pickle module doesn't with the same variables. I'm sure its something obvious. (I've tried

This is the code for the save/load on my program, any pointers would be graciously received (can you also advise on whether is is okay to have a seperate line for each part of the pickle or if it would be better done as a list?).

Stay safe, cheers.

#Main Save Module

def save():

filename = filedialog.asksaveasfilename(defaultextension='.spool', initialdir = "/",title = "Select file",filetypes = ((".spool files","*.spool"),("all files","*.*")))

#filename = filedialog.asksaveasfilename(defaultextension='.spool', initialdir = "/",title = "Select file",filetypes = ((".dat files","*.dat"),("all files","*.*")))

with open(filename, 'wb') as pickle_file:

#input dumps

pickle.dump(OD.get(), pickle_file, pickle.HIGHEST_PROTOCOL)

pickle.dump(WT.get(), pickle_file, pickle.HIGHEST_PROTOCOL)

pickle.dump(Wetwt.get(), pickle_file, pickle.HIGHEST_PROTOCOL)

pickle.dump(Length.get(), pickle_file, pickle.HIGHEST_PROTOCOL)

pickle.dump(extralength1.get(), pickle_file, pickle.HIGHEST_PROTOCOL)

pickle.dump(extralength2.get(), pickle_file, pickle.HIGHEST_PROTOCOL)

pickle.dump(extralength3.get(), pickle_file, pickle.HIGHEST_PROTOCOL)

pickle.dump(extralength4.get(), pickle_file, pickle.HIGHEST_PROTOCOL)

pickle.dump(extralength5.get(), pickle_file, pickle.HIGHEST_PROTOCOL)

pickle.dump(extralength6.get(), pickle_file, pickle.HIGHEST_PROTOCOL)

pickle.dump(extralength7.get(), pickle_file, pickle.HIGHEST_PROTOCOL)

pickle.dump(extralength8.get(), pickle_file, pickle.HIGHEST_PROTOCOL)

pickle.dump(extralength9.get(), pickle_file, pickle.HIGHEST_PROTOCOL)

pickle.dump(extralength10.get(), pickle_file, pickle.HIGHEST_PROTOCOL)

pickle.dump(Materialreadout.get(), pickle_file, pickle.HIGHEST_PROTOCOL)

#result dumps

pickle.dump(Area.get(), pickle_file, pickle.HIGHEST_PROTOCOL)

pickle.dump(Area1.get(), pickle_file, pickle.HIGHEST_PROTOCOL)

pickle.dump(Finalarea.get(), pickle_file, pickle.HIGHEST_PROTOCOL)

pickle.dump(weightest.get(), pickle_file, pickle.HIGHEST_PROTOCOL)

pickle.dump(Wetwt1.get(), pickle_file, pickle.HIGHEST_PROTOCOL)

pickle.dump(Pipevolume.get(), pickle_file, pickle.HIGHEST_PROTOCOL)

def load():

filename = filedialog.askopenfilename(initialdir = "/",title = "Select file",filetypes = ((".spool files","*.spool"),("all files","*.*")))

#filename = filedialog.askopenfilename(initialdir = "/",title = "Select file",filetypes = ((".dat files","*.dat"),("all files","*.*")))

with open(filename, 'rb') as pickle_file:

text = pickle.load(pickle_file)

OD.set(text),

text1 = pickle.load(pickle_file)

WT.set(text1),

text2 = pickle.load(pickle_file)

Wetwt.set(text2),

text3 = pickle.load(pickle_file)

Length.set(text3),

text4 = pickle.load(pickle_file)

extralength1.set(text4),

text5 = pickle.load(pickle_file)

extralength2.set(text5),

text6 = pickle.load(pickle_file)

extralength3.set(text6),

text7 = pickle.load(pickle_file)

extralength4.set(text7),

text8 = pickle.load(pickle_file)

extralength5.set(text8),

text9 = pickle.load(pickle_file)

extralength6.set(text9),

text10 = pickle.load(pickle_file)

extralength7.set(text10),

text11 = pickle.load(pickle_file)

extralength8.set(text11),

text12 = pickle.load(pickle_file)

extralength9.set(text12),

text13 = pickle.load(pickle_file)

extralength10.set(text13),

text14 = pickle.load(pickle_file)

Materialreadout.set(text14),

command = calculate

#result loads

text15 = pickle.load(pickle_file)

Area.set(text15),

text16 = pickle.load(pickle_file)

Area1.set(text16),

text17 = pickle.load(pickle_file)

Finalarea.set(text17),

text18 = pickle.load(pickle_file)

weightest.set(text18),

text19 = pickle.load(pickle_file)

Wetwt1.set(text19),

text20 = pickle.load(pickle_file)

Pipevolume.set(text20),


r/pythonhelp • • Apr 08 '20

Help with an introduction project

2 Upvotes

I'm in an introduction to programming class and I don't actually understand anything. We have a final project on making a very simple game and I need someone who can help me with my milestones leading up to the project. I can't even add graphics and to the class structure for the buttons. My discord is Kenma ~☆#2371 if you'd like to message there.


r/pythonhelp • • Mar 08 '20

HELP!! I’m trying to make a phone book program and i’m very new to this. I don’t know where to call the “last” function to make it continue the program. There are probably a couple of incorrect things in there so if you spot any could you help me with those as well?!!

Post image
2 Upvotes

r/pythonhelp • • Jan 19 '20

a function not working

2 Upvotes

I have a script, and I'm not sure why it isn't working:

def command(string):
	commands = [
	'wireshark',
	'atom',
	'gedit',
	'chrome'
	]
	outputs =  [
	'sudo wireshark',
	'atom',
	'gedit',
	'google-chrome-stable'
	]
	
	for i in range(len(commands)):
		if (string == commands[i]):
			return outputs[i]
			break
		elif not (string == commands[i]):
			W = 1+1
		else:
			return "Error: Command \""+string+"\" not in Torrent commands list."

def main():
	while True:
		string = input('Torrent:~# ')
		L = command(string)
		if (L == string):
			print('ya huh')
		elif (string == 'exit'):
			break
		else:
			print(command(string))


main()

It opens up a prompt until you type in exit, which works fine. when you type in say "chrome", instead of saying 'ya huh', it says 'google-chrome-stable', and when you put in 'blob' for example, it says 'None' instead of the error text which would be "Error: Command "blob" not in Torrent commands list." why?


r/pythonhelp • • Nov 10 '19

Not understanding numpy.random

2 Upvotes

Hey guys,
I really cant get my head around what is happening in this Code. What is numpy.random.multivariate_normal returning. What is x and what is y. And what are those red lines representing. Would be nice if someone could explain like im five. I really dont understand what those samples represent

Note: I am the one who wrote the code, it was an excersice I had to do where I basically just followed what the lection told me to do. Here is the excersice


r/pythonhelp • • Nov 04 '19

Traveling salesman D2 matrix

2 Upvotes

Hello,

I have a 2D matrix (map) with constraints :- 0 are free boxes ;- 1 are boxes to go through ;- 2 are blocked boxes ;- 3 is the start, 4 is the exit ;

0 0 0 0 0 0 0 4
1 2 2 0 0 2 2 1
1 2 2 0 0 2 2 1
0 2 2 0 1 2 2 0
0 2 2 0 1 2 2 0
0 1 1 0 0 1 1 0
0 2 2 0 0 2 2 0
0 2 2 0 0 2 2 0
1 2 2 0 1 2 2 0
1 2 2 0 1 2 2 0
3 0 0 0 0 0 0 0

I need to draw a path walking on all marked boxes (it doesn’t matter if the path is not really optimized), it is possible to walk on a box already traveled.

I would like to find a resource (stack overflow, tutorial, etc.) talking about a similar problem to get an idea of where to start.

Thanks,


r/pythonhelp • • Jun 15 '19

I suck at python so pls help

2 Upvotes

ok so i just started out on python 2 weeks ago and my homework is

c = [(11,22,33), (44,55,66), (77,88,99),(102,103,492), (222,333,444)] print out the sum of c print out the sum of the second, third, and fourth items in c.


r/pythonhelp • • Apr 18 '19

Need 1 pointer with unknown reason for TypeError (Codecademy: Sal's Shipping)

2 Upvotes

Hello all! Python noob here. I am following along with a project on Codecademy for Python 3, and everything was going smoothly until the last step.

The instructions are as follows:

Using those two functions for ground shipping cost and drone shipping cost, as well as the cost of premium ground shipping, write a function that takes one parameter, weight, and prints a statement telling the user the cheapest shipping method and the cost using the chosen method

I tried a few different things, but when I try to add a variable to the string in the return statement, I get a TypeError complaining about implicity converting a float to a str. Everything else works in the program and the function seems to work when I don't try to add anything to the string. I've been stuck for a bit so if someone could give me a pointer or explain why that error is coming up, that'd be very much appreciated. Here is my code:

def ground_shipping(weight):
  if weight <= 2.0:
    cost = 1.50 * weight + 20.00
  elif weight <= 6.0:
    cost = 3.00 * weight + 20.00
  elif weight <= 10.0:
    cost = 4.00 * weight + 20.00
  else:
    cost = 4.75 * weight + 20.00
  return cost

def drone_shipping(weight):
  if weight <= 2.0:
    cost = 4.50 * weight
  elif weight <= 6.0:
    cost = 9.00 * weight
  elif weight <= 10.0:
    cost = 12.00 * weight
  else:
    cost = 14.25 * weight
  return cost

premium_shipping = 125.00

def optimal_shipping(weight):
  if ground_shipping(weight) > drone_shipping(weight):
    return "The cheapest method will be drone shipping, and it will cost $" # how to add cost?
  elif drone_shipping(weight) > ground_shipping(weight):
    return "The cheapest method will be ground shipping, and it will cost $" # + ground_shipping(weight) returns TypeError: cannot convert float to str
  else:
    return "The cheapest method will be premium shipping, and it will cost $" # fix-here

print(ground_shipping(8.4))
print(drone_shipping(1.5))
print(optimal_shipping(4.8))
print(optimal_shipping(41.5))

edit: formatting


r/pythonhelp • • Mar 27 '19

Python problem with tkinter

2 Upvotes

I have a problem with my python code, i can't upload an image with the Tkinter module :full code

I try to put an image in the window (dice.ico) in the middle but i get error at line 3000+ when my code is only 18 line

Sorry for my bad English i'm Albanian and new to python


r/pythonhelp • • Jan 23 '19

I am currently building python 3.5 from source..........

2 Upvotes

I am on Linux and I am currently building python from source. The first steps go all fine, but when I have to make make test it stops on 394 of 397. I interrupted one time and I started again a second time, it stops on the same point. Do I have to .config something or try something else or is it safe to proceed with sudo make install ????


r/pythonhelp • • Jan 22 '19

make [[1, 2],[3, 4],[5, 6,]] Into [[1, 2, 3, 4][5, 6]]

2 Upvotes

This is one of these rare things Im not able to google.

I want to merge 2/3 lists inside a list but leave the third.

so i want to turn:

list = [[1, 2],[3, 4],[5, 6,]]

into

list = [[1, 2, 3, 4][5, 6]]

Whats is my best option?

i could use something like list = [list[0]+list[1]]+list[2:]

But it would be annoying if I for example would want to merge all lists in a list that has the string 'hi' like the example below:

[[1, 2],[''hi, 4],[5, 6,]['hi', 9]] into [[1, 2],['hi', 4,'hi', 9],[5, 6,]]


r/pythonhelp • • Dec 02 '17

Is anyone interested in taking over moderation of this sub?

2 Upvotes

Please PM me!


r/pythonhelp • • Oct 13 '17

Can someone please help me with this syntax error?

2 Upvotes

i am trying to make a program to calculate a taxi company's prices but there is a syntax error in this piece of code:

time = int(input("what time do you want the taxi on a 24 hour clock? ") if time < 8 or time > 20: hourcharge = 2 else: hourcharge = 1


r/pythonhelp • • Jan 13 '17

Please help me with a script - I'm struggling with the count for variables in a list

2 Upvotes

Let me preface this by saying that I'm a total beginner and have been reading from online books. I apologize in advance for the n00b question. I need a script that prompts a user to input their namge, their gender and their age and repeat these questions until they are done. The script runs and does mostly what I expect it to. However, it doesn't seem to be calculating the count correctly for the number of 'M' entries that I've entered into the script. It's calculating the number of 'F' entries just fine. Here is the script that I have put together....

count = 0
total = 0
gender = []
ask = input("Do you want to enter a survey? (Y/N)")
try:
    while ask == "Y":
        age = float(input("Enter your Age : "))
        count = count + 1
        total = total + age
        gender = input("What is your gender - M or F?")
        continued_ask = input("Do you want to continue entering another survey? (Y/N) ")
        if continued_ask == "Y":
            continue
        elif continued_ask == "N":
            print ("The average of", count, "ages is", total / count)
            print ("The total number of Males is", gender.count("M"))
            print ("The total number of Females is", gender.count("F"))
            break
except:
    print ("Average cannot be calculated")

Where have I gone wrong? Please keep in mind that I'm very much a beginner and could use a nudge in the right direction.