[Solved] Need help, got stuck with the python code [closed]

Something like this, where repetitive code is avoided and some error handling for user input: (Plus, you math was a little off, since 50,000, 100,000, and 200,000 are not being handled at all, example: (cost) < 50000 and (cost) > 50001 leaves 50,000 as a gap, since it is neither less than 50,000 or greater … Read more

[Solved] Why do I receive syntax error at n in the line If n % i? [closed]

Correct Code: def prime_chk(upper): print(“Prime numbers between”,0,”and”,upper,”are:”) for num in range(0,upper + 1): # prime numbers are greater than 1 if num > 1: for i in range(2,num): if (num % i) == 0: break else: print(‘Well done! You have found a prime : ‘,num ) n = int(input(‘Number to be checked:’)) prime_chk(n) solved Why … Read more

[Solved] A dictionary that returns number of word and each word’s lenght Python

sample = “i am feeling good” output = {} output[“word”] = len(sample.split()) output[“chars”] = len(list(sample)) for elem in sample.split(): output[elem] = len(list(elem)) print(output) output: {‘word’: 4, ‘chars’: 17, ‘i’: 1, ‘am’: 2, ‘feeling’: 7, ‘good’: 4} solved A dictionary that returns number of word and each word’s lenght Python

[Solved] Python, using nested lists (list of lists) from user input [closed]

So if I’m understanding correctly, the “Lists of List” comment pertains to nested Lists, The code you have is close to what’s needed. I believe this is what you need. print(“Enter First name, last name and Student ID number. Then press 0 to continue”) userFirst = str(input(“Enter First Here:”)) userLast = str(input(“Enter Last Name:”)) userStudent … Read more

[Solved] Python SyntaxError: ‘return’ outside function [closed]

The code of the entire function has to be indented: def _download_track(self, song_url, track_name, dir_name,metadata): if ‘.mp4’ in song_url: track_name = track_name + ‘.m4a’ else: track_name = track_name + ‘.mp3’ file_path = dir_name.replace(“.”,”_”) + “https://stackoverflow.com/” + track_name print((‘Downloading to’, file_path)) if os.path.isfile(file_path): return #print metadata #response = self._get_url_contents(song_url) #with open(file_path,’wb’) as f: #f.write(response.content) r = … Read more

[Solved] How to generate random sampling in python . with integers. with sum and size given

You can use random.gauss to generate 6 numbers around a mean with a certain standard deviation (closeness) and as per @PatrickArtner suggestion construct the 7th one, e.g. using 3 standard devs from mean: In []: import random vals = [int(random.gauss(341/7, 3)) for _ in range(6)] vals.append(341 – sum(vals)) vals, sum(vals), sum(vals)/7 Out[]: ([47, 47, 48, … Read more

[Solved] i have this error can anyone tell me the solution [closed]

As you can see here: http://pandas.pydata.org/pandas-docs/dev/generated/pandas.DataFrame.drop_duplicates.html “subset” is not an authorized keyword for “drop_duplicates” method. I think you can use “cols” instead of “subset”. 1 solved i have this error can anyone tell me the solution [closed]

[Solved] Matplotlib graph adjusment with big dataset [closed]

Given this dataframe: df.head() complete mid_c mid_h mid_l mid_o time 0 True 0.80936 0.80943 0.80936 0.80943 2018-01-31 09:54:10+00:00 1 True 0.80942 0.80942 0.80937 0.80937 2018-01-31 09:54:20+00:00 2 True 0.80946 0.80946 0.80946 0.80946 2018-01-31 09:54:25+00:00 3 True 0.80942 0.80942 0.80940 0.80940 2018-01-31 09:54:30+00:00 4 True 0.80944 0.80944 0.80944 0.80944 2018-01-31 09:54:35+00:00 Create a 50 moving average: … Read more

[Solved] This if statement is not even working correctly

This is a problem with your indentation. You can learn about indentation here: https://docs.python.org/2.0/ref/indentation.html and on the web. To get your code working do the following: string = “A” secret_word = “Apple” if string in secret_word: print(“Good!”) else: print(“Bad…”) 4 solved This if statement is not even working correctly

[Solved] validate date format in python [with regex or any built in method]

you can use datetime for this (in python 2.7) from datetime import datetime date_string = ‘20170808’ if len(date_string) == 8: datetime.strptime(date_string, ‘%Y%m%d’) else: raise ValueError(‘date need to be in format YYYYMMDD ‘) if you date is not valid than you get: a ValueError Exception ValueError: unconverted data remains: 0 2 solved validate date format in … Read more

[Solved] python script from youtube video doesn’t work

I am pretty sure this is all the code needed for the video, It might help as a reference. import urllib import webbrowser import time from xml.etree.ElementTree import parse u = urllib.urlopen(“http://ctabustracker.com/bustime/map/getBusesForRoute.jsp?route=22”) data = u.read() with open(“rt22.xml”, “wb”) as f: f.write(data) f.close() office_lat = 41.980262 doc = parse(“rt22.xml”) def distance(lat1, lat2): ‘Return approx miles between … Read more