Click here to Skip to main content
15,899,679 members
Everything / Programming Languages / Python3.6

Python3.6

Python3.6

Great Reads

by D4rkTrick
This article provides code for making a Thread reusable.
by daubrecq
How to detect queue completion from other threads properly when using Python queues.
by Bill_Hallahan
This is a Python 3.x code generation program that generates Python 3 programs.

Latest Articles

by Bill_Hallahan
This is a Python 3.x code generation program that generates Python 3 programs.
by daubrecq
How to detect queue completion from other threads properly when using Python queues.

All Articles

Sort by Score

Python3.6 

15 Feb 2018 by OriginalGriff
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action. Try it yourself, you may find it is...
14 Dec 2018 by D4rkTrick
This article provides code for making a Thread reusable.
20 Oct 2020 by daubrecq
How to detect queue completion from other threads properly when using Python queues.
7 Jul 2020 by Richard MacCutchan
You declare your Circle constructor as def __init__(self,angle:float=180,**kwargs): but then try to pass values instead of keyword pairs. You need to call it by: Circle(5,x=11,y=22) And the same with your Rectangle. Although with so few...
2 Sep 2020 by Sandeep Mewara
Using Bubble sort, it would be something like: def sortTuple(t): for i in range(0, len(t)): for j in range(0, len(t)-i-1): if (t[j][1] > t[j + 1][1]): #notice here, I have used index 1 to use price as the value ...
2 Sep 2020 by Richard MacCutchan
Try this: newlist=() list=(('CAKE', (748.0, '07-09-2020')), ('JELLY', (12.0, '07-09-2020')), ('CREAM', (244.0, '03-11-2020'))) for element in list: newitem = (element[0], (element[1][1], element[1][0])) newlist = newlist + newitem...
4 Aug 2021 by CPallini
To simplify your task, allocate a bidimensional matrix and assign the corresponding characters inside it. Then print the matrix to the console.
20 Feb 2018 by Richard MacCutchan
That syntax is wrong in two ways. Firstly your text strings are not enclosed in quotes. And secondly you cannot set a function equal to some value. See 6. Modules — Python 3.4.8 documentation[^] for how to define and call functions correctly.
22 Aug 2023 by OriginalGriff
The error message is telling you that there is no such element in the array you are assigning to:hours_worked[emp_count] = int(input('Hours >')) And that is because the array has no elements when you start:hours_worked = [] Instead of assuming...
10 Dec 2023 by Richard MacCutchan
This is a mathematical problem, and needs to be addresses as such. See Knapsack problem - Wikipedia[^]
1 Sep 2017 by Richard MacCutchan
At a guess you need to go through the grade records and look up the student for each one. Using the letter grades you can get the numeric value, and add that to the student total. Once you have added all the grade values you can calculate the averages. You may find it useful to create a class to...
1 Feb 2018 by CPallini
Constructor is __init__ (note double underscores), not _init_
20 May 2018 by OriginalGriff
Simple: X is not greater than or equal to 20. So the loop body is never executed. Try this: x = 20 while x >= 0: print(x) x -=2
25 Jul 2018 by Patrice T
So, you show no attempt to solve the problem yourself, you have no question, you just want us to do your HomeWork. HomeWork problems are simplified versions of the kind of problems you will have to solve in real life, their purpose is learning and practicing. We do not do your HomeWork....
12 Dec 2018 by OriginalGriff
A simple google on the error message takes you right to the solution: cannot import name 'ascii_letters' - Google Search[^] The top link explains the problem and it's solution: Python requests module import error - Stack Overflow[^] If you get an error message you don;t understand, start by...
14 Jun 2019 by Patrice T
Try: import numpy as np h =open('profile_ll.py','r') h_contents = h.read() if h_contents.find('self.binspec') == 57: #line 57 has self.binspec f = open('binspec') for lines in f: print(lines) sck.send('PRIVMSG ' + chan + " " + lines) f.close() ...
11 Nov 2019 by Richard MacCutchan
There is no need to write the interim file, try: oldtext = open("BATCH_ROLLBACK.txt").read() oldtext = oldtext.replace('pyt_batch_id', '123456') newtext = oldtext.replace('123456', 'pyt_batch_id',1) f2 = open('NEWBATCH_ROLLBACK.txt', 'w') f2.write(newtext) f2.close()
1 Jan 2020 by Richard MacCutchan
1. Learn C++ 2. Write the application in C++. Sorry, but this site does not provide free coding or conversion services.
24 Feb 2020 by MadMyche
The problem you are experiencing looks to be caused by having a relationship between the 2 tables involved (share / attachment) and trying to delete an entry from the table with the PrimaryKey.DBAPI Errors IntegrityError Exception raised when...
3 Jun 2020 by CHill60
The value of aid that you are trying to insert into the table ACTOR already exists on that table, and the column has a UNIQUE constraint on it. Either remove the UNIQUE constraint (probably not the right solution) OR check for whether you should...
19 Jun 2020 by Richard MacCutchan
This is the same issue as your previous question at Why the multilevel inheritance doest work ?[^]. You must pass the correct number of parameters to the super class, as clearly stated in the error message. If you do not understand how classes...
25 Jun 2020 by Luc Pattyn
I suspect a typo in line label6=tkinter.Label(root, test='Selece Co', width=20) :)
30 Oct 2020 by Richard MacCutchan
You are not doubling numbers, you are modifying strings of characters. The fact that they are digits is irrelevant. So all you need is something simple such as: s= ["110", "212", "39839", "ABC" ] index = 0 while index
5 May 2021 by OriginalGriff
Because "40 30" is not an integer, so if you input it to start with you will get an error saying that: for _ in range(int(input())): If you enter it at your second input, then the split generates a list which isn't convertible directly to an...
8 May 2021 by Patrice T
Quote: time limit exceed. This usually mean that your code is too simple minded and that is at the expense of runtime. Think of a multiplication x*y, you can add x, y times to a total, it works, but it is not efficient. You have the same kind of...
13 Jun 2021 by Patrice T
i dont know what should i do any idea whats the issue? The issue is that you didn't read the documentation. It happen the programming languages are no plain english, you need to learn how to express what you want to do. This is not Python: if...
4 Jul 2021 by CPallini
sum is undefined. Try def function(n): if n == 0: return 0 else: return n + function(n - 1) n = 5 print(function(n))
29 Jul 2021 by OriginalGriff
Python allows negative indexes to lists, with -1 being the last item, -2 the second to last, and so forth. So your code: my_list = [3, 1, -2] print(my_list[my_list[-1]]) Is the equivelant of: index = my_list[-1] print(my_list[index]) Since -1...
15 Oct 2021 by OriginalGriff
Read the error message: File "main_S3DIS.py", line 123, in spatially_regular_gen center_point = points[point_ind, :].reshape(1, -1) IndexError: index 319979 is out of bounds for axis 0 with size 47722 Your index value is way too big. We...
4 Nov 2021 by Richard MacCutchan
Assuming that you are using tkinter (which you omitted to mention), then you need the following: import tkinter as tk root = tk.Tk() You will most likely need to use the tk. prefix on all your controls also, as shown below: import tkinter...
20 Jan 2022 by M Imran Ansari
Try the following link: Python program to print the binary value of the numbers from 1 to N - GeeksforGeeks[^]
21 Jan 2022 by Luc Pattyn
too much code. Some analysis will proof that, when using base 10, the two-digit number [ab] is a "special number" if and only if b is 9. start with: 10*a + b = a + b + a*b
22 Feb 2022 by CPallini
Based on the requirements ("Sort the unsorted elements and square the elements in it"), the output you are getting is correct. If you really wish to obtain a sorted list of squares, then you have first to generate a list of squares and then sort...
25 Feb 2022 by OriginalGriff
Stop and think about what you are trying to do instead of trying to dive right into code. Yes, split it into separate words, but after that you need to work out which words are repeated exactly twice, and there is a trick to that: sorting. If...
5 Apr 2022 by OriginalGriff
You don't, because you're mixing types and assuming that the result will be useful - it won't any more than adding two mobile phone numbers together produces a useful phone number. What you can do is convert the whole thing to a string and use...
24 Apr 2022 by CHill60
Quote: my issue done when change column name from studentname to Name on table students If you are changing the name of the column then obviously the header of the column will also change to match the name of the column. You are exporting the...
11 May 2022 by OriginalGriff
While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for...
11 May 2022 by Richard MacCutchan
See The Python Tutorial — Python 3.10.4 documentation[^]
15 Jun 2022 by CPallini
Try the following code n=3 adjacency_matrix =[ [2, 3, 0] , [0, 0, 1] , [1, 5, 0] ] li_r = [] li_c = [] for i in range(n): for j in range(n): if adjacency_matrix[i][j]!=0: li_r.append(i) li_c.append(j) print(li_r) print(li_c) ...
24 Aug 2022 by CPallini
Try n = int(input()) Tuple1 = namedtuple("Cols", input()) s = 0 Names = [] for i in range(n): sp = Tuple1(*input().split()) s += int(sp.MARKS) Names.append(sp.NAME) print(s) print(Names) print(s/n)
10 Nov 2022 by Bill_Hallahan
This is a Python 3.x code generation program that generates Python 3 programs.
25 Jan 2023 by Richard Deeming
Your original code iterates over the list in the order of N+1 times - once to generate a set of unique values, and once for each unique value to count the number of occurrences. Your dictionary code also iterates over the list in the order of...
15 Feb 2023 by Sandeep Mewara
Quote: Ques 1. x=+1 This will always be 1 as it's an assignment not an increment. If you do x+=1 without initializing, it will throw an error. Quote: Ques 2. output:4,12 This happened as during the compiler run, value of b was already defined...
21 Feb 2018 by CPallini
Do you mean something similar to class function: def createtextfile(self, text): f = open('foo.txt','w') f.write(text) f.close() def addtext(self): f = open('foo.txt','a') something = input('what would you like to add? ') f.write(something)...
17 Apr 2023 by OriginalGriff
The reason it is not what you needed is that it's a solution to a different problem. You can't just find code on the internet and assume that it will do what you need to hand in, or that anyone else is going to force it to do what your teacher...
15 Nov 2023 by Maciej Los
Take a look at the content of response_json variable: {'coord': {'lon': -86.1772, 'lat': 39.7778}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01d'}], 'base': 'stations', 'main': {'temp': 63.86, 'feels_like':...
11 Jan 2024 by Richard MacCutchan
This says print "Guess" to the console, and wait for input. When something is typed in, try to convert it to an integer value and store the value in the varaible named Guess. Guess = int(input("Guess") : This says add 1 to the variable named...
13 May 2021 by raddevus
==>> TypeError: 'int' object is not iterable – You are attempting for loop over the units object. for currentUnit in units Most likely the units object is not a collection and so it is failing.
N 6 May 2024 by Dave Kreskowiak
You may have better luck using the Facebook and Instagram API's instead of scraping. https://developers.facebook.com/docs/graph-api/[^] https://developers.facebook.com/docs/instagram/[^]
4 Aug 2017 by Thomas Daniels
There is no "better", because they have different purposes: .append adds a single element to the list. .extend is like append but for multiple elements: it takes a list as argument. a += [3, 5] is short-hand for a = a + [3, 5] and this does the same as extend, but the difference is that the +...
20 Aug 2017 by Richard MacCutchan
Start by counting the number of occurrences of each value. You also need some way to store this information, so look at the collection types that can keep two values together in this way: maybe a dictionary. Once you have that information you can find the minimum and maximum occurrences. And...
2 Oct 2017 by OriginalGriff
Refactor your code: move both loops into a function, and replace the break with a return.
14 Oct 2017 by OriginalGriff
What you are looking for is the largest product of two numbers in a list: which means multiplying each pair and comparing each against the previous maximum, not just printing each product. So try this: 1) Create a variable outside the loop, call it maxSoFar and set it to the product of the first...
17 Jan 2018 by Richard MacCutchan
Probably because your call to sys.exit() is not indented, so is not part of the exception handler, but executed immediately after the try/except block.
27 Jan 2018 by Thomas Daniels
Both newjoke and the code in the while loop will ask "Did you find that funny?". So, what you see is the question getting repeated because after newjoke get called, you'll go back to the beginning of the while loop. This gives the impression of displaying a blank joke, but you just didn't hit...
27 Jan 2018 by Thomas Daniels
print("\nWell what about this:\n\n",joke) print("a", "b") will print a b with a space in-between. That's what's happening here too: it prints the "What about this" with the newlines, then a space, then the joke. Try this instead: print("\nWell what about this:\n\n" + joke)
1 Feb 2018 by CPallini
Quote: prof= "fighter" You probably meant self.prof = "fighter"
16 Feb 2018 by Patrice T
In your code, you missed: Quote: 1. First, determine the total number of centimeters. And this matters because meters and centimeters and not exact multiples of inches and foot. Advice: Take a sheet of paper and a pencil, practice the conversion with examples until you master the algorithm....
23 Feb 2018 by RickZeeland
I think you need a Visual C++ redistributable, see explanation and downloads here: Microsoft Visual C++ Redistributable All Versions Direct Download Links[^] It is sadly necessary to have a lot of them installed, only the newest version is not enough !
18 Mar 2018 by Richard MacCutchan
Your formatting leaves much to be desired. However, you can simplify things by checking the values as you go through the initial loop, like this: flavours = ["Vanilla", "Chocolate", "Mint Choc Chip", "Rosewater", "Strawberry", "Mango", "Frutti Tutti", "Fudge Brownie", "Bubblegum",...
1 Apr 2018 by Member 13757541
I've been having a problem with installing packages in PyCharm. This started happening a few months ago, but before that it was fine. I can install it from the cmd using pip, but when I try to import it into the IDE it gives this error: ModuleNotFoundError: No module named '_winreg' and...
4 Apr 2018 by Patrice T
Try to replace print('n\Keys:',dict.keys() del dict[ 'name' ] with print('n\Keys:',dict.keys()) del dict[ 'name' ]
30 May 2018 by Patrice T
Quote: In my program, if I delete the return-1 statement I get the right answer but otherwise it keeps returning -1. Why does it keep doing so? Because with this code you get -1 if first letter is not an operator. Try def findNextOpr(txt): #txt must be a nonempty string. if...
7 Jun 2018 by Maciej Los
Member 13861803[^] wrote: but if statement dosent work. why is it? It's obvious! As Richard MacCutchan[^] mentioned in the comment to the question, there's no if statement in your code! Go back to basics: Python - Arrays[^] Python IF...ELIF...ELSE Statements[^]
7 Jun 2018 by CPallini
Have also a look at: Find Duplicate numbers in list | GeoNet[^].
14 Jun 2018 by Jochen Arndt
So you want to get the time stamp and the part at the end? While this can be done with regular expressions, it would be much simpler (and faster) with classic string operations. The time stamp is at the begin of the line with a fixed lenghth of 23 and the end part is after the last space in...
4 Jul 2018 by CPallini
fhand=open('demo.txt') for line in fhand: line=line.rstrip() if( line.find('python') != -1): print(line)
4 Jul 2018 by Richard MacCutchan
The find method returns the index to the first occurrence of the find target. You are only printing the ones where the index is zero. Change your loop to: for line in fhand: line=line.rstrip() if(line.find('python') != -1): print(line) In future please format your code properly...
7 Jul 2018 by Patrice T
Quote: I want to learn python programming but don't know from where to start learning. What should i learn and from where can i get material to learn. 'learn python programming' covers 2 different things: learn Python as a new language and learn programming. It is the same difference as getting...
25 Jul 2018 by CPallini
It is very simple once you realize you have to choose the letter based on current distance from central letter, where the distance function is max (|x-L| , |y-L|) (Where L is the length of the string) Try def distance(x,y,l): return max( abs(x-l), abs(y-l)) s = "CODEPROJECT" l = len(s)...
15 Aug 2018 by OriginalGriff
Recursion is simple to understand: see "recursion" and it'll all be clear! Your function calls itself with different parameters, and return to itself with the value each time when it's calculated. Look at what happens with your code when you pass specific values: a == 2, b == 3 1) 2, 3 : b...
17 Aug 2018 by Patrice T
So, you show no attempt to solve the problem yourself, you have no question, you just want us to do your HomeWork. HomeWork problems are simplified versions of the kind of problems you will have to solve in real life, their purpose is learning and practicing. Quote: I do not know how to...
3 Sep 2018 by Richard MacCutchan
It is because your list contains strings and not integers. Sorting in string order, "19" will come before "3", etc.
17 Sep 2018 by Richard MacCutchan
Stop using compound statements like this below. You cannot be certain (and we definitely cannot) what is the result at each part. Split it into discrete elements so you can see the results at each step. You can then display interim values and see where it is going wrong. value =...
11 Oct 2018 by Richard MacCutchan
It should be possible, see https://docs.python.org/3.4/tutorial/controlflow.html#keyword-arguments[^].
14 Nov 2018 by Richard MacCutchan
You are trying to replace the complete text of the second file that occurs in the first. But that text does not exist in the first file, only a part of it. You should read the second file line by line and try the replace on just the text of that line. Something like: import re newcontent:...
15 Nov 2018 by Afzaal Ahmad Zeeshan
So basically you need a service that listens to the file updates. Python itself is merely a language, and does not know the runtime or OS features—debatable, yes, but let's spare the OP from such technical details please. That is why, none of the languages has this feature. C++, C#, Java, none....
15 Nov 2018 by OriginalGriff
That's not good - "18 years old" as an adult is not just a case of "year - x". See here: Working with Age: it's not the same as a TimeSpan![^] - it's C# based, so you can;t use it directly, but it's pretty simple stuff so you should be able to work out what to do in Python.
1 Dec 2018 by OriginalGriff
Because it won't automatically convert types. Try: print("I am " + str(character_age) + ",")
1 Dec 2018 by OriginalGriff
This is exactly the same problem you had last time: Why I am getting an error code in Python?[^] Heck, even the error message is the same, barting the type! So, predictably enough, the solution is the same as well: learning_subject = "Python" print("Learning " + str(learning_subject.isupper()))
7 Dec 2018 by Richard MacCutchan
You need a timer that will interrupt your code, or a separate thread that can signal you when a number of seconds have elapsed. See threading — Thread-based parallelism — Python 3.7.1 documentation[^] and threading — Timer[^].
9 Dec 2018 by Patrice T
It is all in the error message ! script, user_name = argv ValueError: not enough values to unpack (expected 2, got 1) The code want 2 values, but argv got only one.
7 Jan 2019 by Slacker007
I think regular expressions would help you here. Regular Expression HOWTO — Python 3.7.2 documentation[^]
10 Jan 2019 by MadMyche
Quote: remote: -----> Python app detected remote: ! Requested runtime (python-3.7) is not available for this stack (heroku-18). remote: ! Aborting. More info: https://devcenter.heroku.com/articles/python-support The messages explain it all; the version of Python you requested (3.7) is not...
16 Jan 2019 by Member 14120258
For Sklearn 18 version import this: "from sklearn.cross_validation import KFold" For sklearn 20 import this: "from sklearn.model_selection import KFold"
25 Jan 2019 by CPallini
let is the current 'enumerated' item of the list (whereas i is the corresponding index). I think the best way for understanding such a code is by mental (pencil and paper are optional) execution: try to execute mentally the following code: l = ["a","b","c"] permute(l)
9 Feb 2019 by OriginalGriff
This is fundamental to how classes (and OOPs generally) works, so it's important you understand this well. I'd strongly suggest you go back over the last couple of lectures and their notes (and chapters in any course book you are reading) because you seem to have missed all the important stuff. ...
17 Feb 2019 by Bryian Tan
That case, you can update the code to check for type if not type(room) is int: to print out the exception, try import sys except: print("Unexpected error:", sys.exc_info()[0]) Example: CP_hotel | Pyfiddle[^] error handling - How to print an exception in Python? - Stack...
7 Mar 2019 by Afzaal Ahmad Zeeshan
That is a question that includes 2 questions, one about the data type, and second the purpose of that placement. First of, as Solution 1 answers, that is a string definition. In Python, you are not restrained to use a single quote to create a string, you can use multiple ways and this triple...
7 May 2019 by Christian Graus
elif i > 151: if i 151 && i
9 May 2019 by Richard MacCutchan
Well I cannot believe that this works in 2 but not in 3. So, I just tried this again with Python 3.7 and it works perfectly. What I did notice, which was different from my tests yesterday, was the addition of the line #define PY_SSIZE_T_CLEAN before the include of Python.h, as described at...
26 May 2019 by Richard MacCutchan
You are repeatedly requesting a system resource (the PiCamera) inside your while loop until the system has no more. Move the following line outside the loop: camera = PiCamera()
24 Jul 2019 by Gerry Schmitz
Computers are still not "human". There is no "learning" without (initial) "training" (data) in the case of "artificial intelligence". Note the absence of "knowledge" in that phrase. We can train ourselves and gain knowledge; computers not so much. Without knowing cause and effect (i.e....
24 Jul 2019 by Afzaal Ahmad Zeeshan
Quote: the way to label it We can start here. Computer algorithms need enough data to perform their tasks. In machine learning, the learning tasks are categorized as supervised or unsupervised. In supervised learning you provide the data with independent and dependent variables; your input...
13 Aug 2019 by Patrice T
Quote: I tried adjusting the spacing but I am getting the following error again and again. The problem is the number of spaces for i,row in train_df.iterrows(): # in this loop if row['Age']>0 and row['Age']
8 Sep 2019 by Patrice T
Quote: Code is ready and working, but GIT shows incorrect as far as I can see, your usage of 3 spaces as indentation is perfectly legal, but Git want 4 spaces. "indentation is not a multiple of four"
11 Sep 2019 by Patrice T
Sure, I can just give you a full blowup solution, but I am not sure you will learn something. As it is very basic understanding of Python and programming, I think it is better to give you leads and a link to a good tutorial. # Because of print(dec_to_binary(145)) # -> 10010001 # and ...
11 Sep 2019 by Richard MacCutchan
Try the following. You may need to modify some part of it to meet your own criteria, but it does the basics. def binary_to_dec(binary: str) -> int: """ Uses the ord() builtin to get the numeric value of a character Subtracting the ord('0') gets the integer value of the digit ...