Python 3: Exercises And Solutions. - Programming (5) - Nairaland
Nairaland Forum › Science/Technology › Programming › Python 3: Exercises And Solutions. (11949 Views)
| Re: Python 3: Exercises And Solutions. by HappyPagan: 1:28am On May 25, 2020 |
jayphe:
|
| Re: Python 3: Exercises And Solutions. by SKYQUEST(m): 9:40pm On May 28, 2020 |
nwele2017:lets try this! |
| Re: Python 3: Exercises And Solutions. by SKYQUEST(m): 9:58pm On May 28, 2020*. Modified: 10:17pm On May 28, 2020 |
SKYQUEST:how about this: import pandas as pd from pandas import DataFrame df = pd.read_excel('ben2.xlsx',names=['Benf']) #seperate each of the column elements into different list a = df.Benf.str.split().str[0].tolist() b = df.Benf.str.split().str[1].tolist() c = df.Benf.str.split().str[2].tolist() d = df.Benf.str.split().str[3].tolist() df=pd.DataFrame() #create an empty dataframe df['First Digit']=a #add the first column to the dataframe and name it First Digit df["Benford's Set"]=b df['Data Set X']=c df['Deviations']=d df ....to yield this:
|
| Re: Python 3: Exercises And Solutions. by iCode2: 1:30pm On Jun 03, 2020 |
For this code: text = input('Enter a string: ')If i type in 'amalgamate', I'll get the following output: 0,2,5,7, Question: How can I discard that comma after 7? |
| Re: Python 3: Exercises And Solutions. by HappyPagan: 3:57pm On Jun 03, 2020 |
@iCode2 The comma is there because you use end = ',' On line 4. If you want to remove the final comma, you can save the final output in a string and use one of the string methods to remove the last comma. If you want to remove all the commas, maybe you prefer spaces, use end = ' ' #there is a space between both quotes. |
| Re: Python 3: Exercises And Solutions. by Shepherdd(m): 4:39pm On Jun 03, 2020 |
@ jayphe Collinsanele gbolly1151 kensmoney StevDesmond Please let's roll in more exciting challenges. The thread is winding down. |
| Re: Python 3: Exercises And Solutions. by gbolly1151(m): 7:30pm On Jun 03, 2020 |
Shepherdd:Write a recursive function to reverse a list |
| Re: Python 3: Exercises And Solutions. by iCode2: 7:57pm On Jun 03, 2020 |
HappyPagan:Thanks a lot. I'll try that string method and see. |
| Re: Python 3: Exercises And Solutions. by HappyPagan: 8:03pm On Jun 03, 2020 |
iCode2:No wahala. I think rstrip will work. 'astring'.rstrip(',')I'm not on my PC now. Will try it once I get home. |
| Re: Python 3: Exercises And Solutions. by Shepherdd(m): 8:36pm On Jun 03, 2020 |
gbolly1151:Nice one def reverse(data): |
| Re: Python 3: Exercises And Solutions. by gbolly1151(m): 9:01pm On Jun 03, 2020 |
Shepherdd:Good job boss....i will be back with graph question |
| Re: Python 3: Exercises And Solutions. by Shepherdd(m): 9:08pm On Jun 03, 2020 |
gbolly1151:I did some renaming after prototyping inside IDLE.
|
| Re: Python 3: Exercises And Solutions. by gbolly1151(m): 9:12pm On Jun 03, 2020 |
Guy...this is advance question and it is base on graph data structure,i myself haven't try to solve it but you can give it a try and test your data structure skill Write a program that builds the routing tables for the nodes in a computer network, based on shortest-path routing, where path distance is measured by hop count, that is, the number of edges in a path. The input for this problem is the connectivity information for all the nodes in the network, as in the following example: 241.12.31.14: 241.12.31.15 241.12.31.18 241.12.31.19 which indicates three network nodes that are connected to 241.12.31.14, that is, three nodes that are one hop away. The routing table for the node at address A is a set of pairs (B,C), which indicates that, to route a message from A to B, the next node to send to (on the shortest path from A to B) is C. Your program should output the routing table for each node in the network, given an input list of node connectivity lists, each of which is input in the syntax as shown above, one per line. |
| Re: Python 3: Exercises And Solutions. by iCode2: 11:42pm On Jun 03, 2020 |
HappyPagan:I don't know this astrip kini yet. I'll read up on it. |
| Re: Python 3: Exercises And Solutions. by modash(m): 3:01am On Jun 04, 2020 |
Taofeekdboy:The site looks real good. |
| Re: Python 3: Exercises And Solutions. by iCode2: 4:04pm On Jun 04, 2020 |
I've tried my hands on this though. I want to see if someone can answer it a different way. Maybe yours will be better. Write a program that asks the user to enter a list of integers. Do the following: (a) Print the total number of items in the list. (b) Print the last item in the list. (c) Print the list in reverse order. (d) Print Yes if the list contains a 5 and No otherwise. (e) Print the number of fives in the list. (f) Remove the first and last items from the list, sort the remaining items, and print the result. (g) Print how many integers are less than 5 |
| Re: Python 3: Exercises And Solutions. by scarplanet(m): 7:28pm On Jun 04, 2020 |
iCode2:. |
| Re: Python 3: Exercises And Solutions. by scarplanet(m): 7:31pm On Jun 04, 2020 |
class Solution: |
| Re: Python 3: Exercises And Solutions. by Taofeekdboy(m): 9:52pm On Jun 04, 2020 |
modash:Thank you bro... |
| Re: Python 3: Exercises And Solutions. by iCode2: 10:58pm On Jun 04, 2020 |
scarplanet:Chai! Yours looks so advanced.class Solution: I still have a long way to go. Here's my solutionmyList = eval(input('Enter a list of integers)) #Enter the numbers as well as the square brackets. |
| Re: Python 3: Exercises And Solutions. by Shepherdd(m): 11:38pm On Jun 04, 2020 |
gbolly1151:I was once asked a question similar to this and I failed graciously. Now let me tackle it again!! |
| Re: Python 3: Exercises And Solutions. by gbolly1151(m): 10:03pm On Jun 05, 2020 |
Give a recursive algorithm to compute the product of two positive integers, m and n, using only addition and subtraction. |
| Re: Python 3: Exercises And Solutions. by IamGoke(m): 4:35pm On Jun 07, 2020 |
jayphe:Nice initiative bro. I was able to extract 'www.thapar.edu' with regex.
|
| Re: Python 3: Exercises And Solutions. by Jummate(m): 11:57pm On Jun 08, 2020 |
gbolly1151:def product(m, n): if n == 0: return 0 else: return m + product(m, n-1) |
| Re: Python 3: Exercises And Solutions. by Jummate(m): 12:12am On Jun 09, 2020 |
Jummate:I indented lines 2 and 4 to be under the function declaration. I indented lines 3 to be under the if statement and line 5 to be under the else statement but I don't know why these are not reflecting as such........ |
| Re: Python 3: Exercises And Solutions. by IamGoke(m): 2:29pm On Jun 09, 2020 |
Jummate:If you are writing code, you need to format your text in code format. [Code] #Your code here [/Code] Change the C to c Example below: print('hello word') |
| Re: Python 3: Exercises And Solutions. by Jummate(m): 3:47pm On Jun 09, 2020 |
IamGoke:
|
| Re: Python 3: Exercises And Solutions. by Shepherdd(m): 9:21pm On Jun 09, 2020 |
gbolly1151:Although this question does not provide the routing table I made some assumptions. routing_table = {Although their might be multiple route to a destination I avoided implementing this for brevity. DS & Algo questions sometimes aren't easy!!! |
| Re: Python 3: Exercises And Solutions. by gbolly1151(m): 3:55am On Jun 10, 2020 |
Shepherdd:You have done a great job here bro....graph and tree questions aren't friendly |
| Re: Python 3: Exercises And Solutions. by razboy20: 7:30am On Jun 10, 2020 |
input = str(input("Enter a string: " )arr = input.split(" " ![]() print(join(arr,"_" ) |
Enroll Free : The Ultimate Python 3.9 Programming 2021 A-Z Masterclass • Salesforce Rest API Example Using Python 3 • Consume Kibana Rest API Using Python 3 • 2 • 3 • 4
Why Is It That The Things That Give Money In Tech Are Always Hidden? • How I Switched To Data Science From A Non IT Background - My Learning Experience • I Buy AMAZON AWS Accounts. You Can Create And Sell To Me.

I still have a long way to go. Here's my solution