[Solved] Python simple code i cant fix help1!1

This should fix it: def print_guessed(secret_word): return ‘-‘*len(secret_word) The problem with your code is that you are trying to modify a string by its index. However str object in Python is not mutable. You have to construct a new string. Note that this function returns the same result as other people have proposed. However it … Read more

[Solved] Can I use ‘,’ instead of ‘as’ python 3

The old syntax is no longer valid. Source In Python 2, the syntax for catching exceptions was except ExceptionType:, or except ExceptionType, target: when the exception object is desired. ExceptionType can be a tuple, as in, for example, except (TypeError, ValueError):. This could result in hard-to-spot bugs: the command except TypeError, ValueError: (note lack of … Read more

[Solved] Hi , i am executing a python script using php but I do not want the page to refresh when a button is clicked because i have embedded other pages too [closed]

Use JQUERY Ajax $.post(“url to process data”,{data:data}, function(response){ //do something with the response )}; 5 solved Hi , i am executing a python script using php but I do not want the page to refresh when a button is clicked because i have embedded other pages too [closed]

[Solved] How to input a player name?

In python 2, raw_input will return a string while input will return an evaluated string. Therefore input works fine for the numbers, since eval(‘2’) gives 2 (as an integer). However it does not work for the name, and hence eval(“John”) throws an error. I would recomment to use raw_input throughout your code. For the numbers … Read more

[Solved] patterns in python-complex

You can use the following code: def upanddown(n): return range(1, n) + range(n, 0, -1) def triangle(rows): for num in xrange(1, rows + 1): print ‘ ‘.join(map(str, upanddown(num))).center(rows * 4 – 3) rows = input(“Number of rows: “) triangle(rows) Output: Number of rows: 4 1 1 2 1 1 2 3 2 1 1 2 … Read more

[Solved] pip install pyaudio error cl.exe failed

Prebuilt wheels of PyAudio are currently available for Python 2.7 and 3.4-3.6. If you don’t want to use Python 3.6 and want to install PyAudio in 3.7 you have to compile and install PortAudio and PyAudio from sources. See the instructions at http://portaudio.com/docs/v19-doxydocs/tutorial_start.html https://smaudet.wordpress.com/2014/01/26/building-pyaudio-on-windows-7-x64-using-the-free-msvc-toolchains/ solved pip install pyaudio error cl.exe failed

[Solved] Signal Correlation in python [closed]

You can use scipy.signal.resample for that. # Generate a signal with 100 data point import numpy as np t = np.linspace(0, 5, 100) x = np.sin(t) # Downsample it by a factor of 4 from scipy import signal x_resampled = signal.resample(x, 25) # Plot from matplotlib import pyplot as plt plt.figure(figsize=(5, 4)) plt.plot(t, x, label=”Original … Read more

[Solved] How to sort python dictionary/list?

Assuming I understood your question, these should do it: for person in sorted(cat1): print(person, max(cat1.get(person))) result: ben 9 jeff 6 sam 9 then: for person in sorted(cat1, key=lambda x: max(cat1.get(x)), reverse=True): print(person, max(cat1.get(person))) result: ben 9 sam 9 jeff 6 then: for person in sorted(cat1, key=lambda x: sum(cat1.get(x))/len(cat1.get(x)), reverse=True): print(person, sum(cat1.get(person))/len(cat1.get(person))) result: ben 7.666666666666667 sam … Read more