Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,150,852 members, 7,810,280 topics. Date: Saturday, 27 April 2024 at 04:49 AM |
Nairaland Forum / Science/Technology / Programming / Python 3: Exercises And Solutions. (8867 Views)
Salesforce Rest API Example Using Python 3 / Consume Kibana Rest API Using Python 3 / How To Write A Guessing Game Program In Python 3 (2) (3) (4)
(1) (2) (3) (4) (5) (6) (Reply) (Go Down)
Re: Python 3: Exercises And Solutions. by iCode2: 2:07pm On Jun 10, 2020 |
Write a program that asks the user to enter a sentence and then randomly rearranges the words of the sentence. Make sure that the sentence that will be printed out starts with a capital, that the original first word is not capitalised if it comes in the middle of the sentence, and that the period is in the right place. |
Re: Python 3: Exercises And Solutions. by gbolly1151(m): 7:02pm On Jun 11, 2020 |
iCode2:Can you cite example out input and output? |
Re: Python 3: Exercises And Solutions. by gbolly1151(m): 7:06pm On Jun 11, 2020 |
Question to check your data structure and algorithm skill When a share of common stock of some company is sold, the capital gain (or, sometimes, loss) is the difference between the share’s selling price and the price originally paid to buy it. This rule is easy to understand for a single share, but if we sell multiple shares of stock bought over a long period of time, then we must identify the shares actually being sold. A standard accounting principle for identifying which shares of a stock were sold in such a case is to use a FIFO protocol—the shares sold are the ones that have been held the longest (indeed, this is the default method built into several personal finance software packages). For example, suppose we buy 100 shares at $20 each on day 1, 20 shares at $24 on day 2, 200 shares at $36 on day 3, and then sell 150 shares on day 4 at $30 each. Then applying the FIFO protocol means that of the 150 shares sold, 100 were bought on day 1, 20 were bought on day 2, and 30 were bought on day 3. The capital gain in this case would therefore be 100·10+20·6+30·(−6), or $940. Write a program that takes as input a sequence of transactions of the form “buy x share(s) at $y each” or “sell x share(s) at $y each,” assuming that the transactions occur on consecutive days and the values x and y are integers. Given this input sequence, the output should be the total capital gain (or loss) for the entire sequence, using the FIFO protocol to identify shares. |
Re: Python 3: Exercises And Solutions. by Brukx(m): 7:25pm On Jun 11, 2020 |
iCode2: import random def main() : sentence=input("enter a sentence: " ) list=sentence.split(" " ) new_sentence= random.shuffle(list) new_sentence.capitalize(0) new_sentence.replace(.,"" new_sentence(len(new_sentence))+("." ) print (', '.join(new_sentence)) main() |
Re: Python 3: Exercises And Solutions. by iCode2: 8:09pm On Jun 11, 2020 |
gbolly1151:Input: This boy is a love child of a love God. Output could be: Child god love this a boy is love a of. |
Re: Python 3: Exercises And Solutions. by iCode2: 8:13pm On Jun 11, 2020 |
Brukx:I got a syntax error from line 7. |
Re: Python 3: Exercises And Solutions. by gbolly1151(m): 11:43pm On Jun 11, 2020 |
iCode2:
please check |
Re: Python 3: Exercises And Solutions. by iCode2: 11:54pm On Jun 11, 2020 |
gbolly1151:Wow it worked! Thanks man. I didn't know about that capitalise method. You're good man. |
Re: Python 3: Exercises And Solutions. by gbolly1151(m): 12:02am On Jun 12, 2020 |
iCode2:There is a bug that i fix just now,i remove initial (.) From the sentence to avoid two (.) |
Re: Python 3: Exercises And Solutions. by Brukx(m): 12:25am On Jun 12, 2020 |
iCode2:I've modified it. Check it again |
Re: Python 3: Exercises And Solutions. by iCode2: 7:07am On Jun 12, 2020 |
Brukx:Same thing sir. |
Re: Python 3: Exercises And Solutions. by iCode2: 7:11am On Jun 12, 2020 |
gbolly1151:Still worked. gbolly1151:I didn't notice the bug with the first one though. |
Re: Python 3: Exercises And Solutions. by DAramis: 11:59am On Jun 30, 2020 |
Hello bosses and Madams, Someone should help me out in this python program (I justed started learning it but was stuck in this assignment). The question is in red while my answer is in blue. Who are you? I'm fine, thanks. Who are you? Who are you? Joe Hello, Joe. What is the password? (It is a fish.) Mary Who are you? Joe Hello, Joe. What is the password? (It is a fish.) swordfish Access granted. My code (though not running) name = '' While not name: print ('Who are you?') name = input () while name != 'Joe': print ('Who are you?') break print ('Hello Joe. What is the password?' (it is fish)) password = input () while password != 'swordfish' print ('Hello Joe. what is the password?' (it is fish)) break print ('Access granted') |
Re: Python 3: Exercises And Solutions. by Shepherdd(m): 12:12pm On Jun 30, 2020 |
DAramis: Your first two loops are redundant. Try and merge them into something like secret_name = "Joe" name = input('what is your name') while name != secret_name: name = input('what is your name') Then do the same for the password. It's called sentinel controlled loop. 1 Like |
Re: Python 3: Exercises And Solutions. by DAramis: 3:21pm On Jun 30, 2020 |
Shepherdd:Thanks for the effort. I did it but didn't work. You can write the full code for me to have an idea if my request is not to much. Below is the code: secretName = 'Joe' name = input ('What is your name?') while name != secretName: name = input ('What is your name?') break secretPassword = 'swordfish' password input ('What is your password?') while password != secretPassword: password = input ('What is your password?') |
Re: Python 3: Exercises And Solutions. by Shepherdd(m): 4:07pm On Jun 30, 2020 |
DAramis: |
Re: Python 3: Exercises And Solutions. by DAramis: 7:31pm On Jun 30, 2020 |
Shepherdd: Thanks, would try it out tomorrow and give you feedback. Spanish clasico is starting in few hours Need to watch the match. |
Re: Python 3: Exercises And Solutions. by DAramis: 9:21am On Jul 01, 2020 |
Shepherdd:Copied it exactly like this and pasted on the IDP. It worked right now. Thanks. |
Re: Python 3: Exercises And Solutions. by rastaxarm(m): 1:06am On Jul 02, 2020 |
A Voting System WebApp created with Python/Flask Home Page: https://digitavote.pythonanywhere.com VOTING LIVE VIEW: https://digitavote.pythonanywhere.com/vote/view/live/ Equipped with dashboard. Good for schools and organization elections Still under development
|
Re: Python 3: Exercises And Solutions. by NettyNelly(m): 7:59pm On Jul 12, 2020 |
gbolly1151: What modules do I need to import to solve this.? I used queue and random modules, but seems something is missing. Bro, do share the solution with us. Seems none of us has a a good solution. |
Re: Python 3: Exercises And Solutions. by gbolly1151(m): 11:10pm On Jul 12, 2020 |
NettyNelly: I will try and solve it and release the answer tomorrow |
Re: Python 3: Exercises And Solutions. by gbolly1151(m): 11:13pm On Jul 12, 2020 |
NettyNelly:Queue is FIFO so you can use it,but the real data structure to use in real world should be Priority Queue |
Re: Python 3: Exercises And Solutions. by gbolly1151(m): 12:24pm On Jul 13, 2020 |
NettyNelly: Here is what i solve long time ago and works
|
Re: Python 3: Exercises And Solutions. by Etinosa1234: 8:23pm On Jul 14, 2020 |
jayphe: I'm Learning Java so I Jus decided to use it to strengthen my grip on the language package com.Package; public class Exercises { public static void main(String args[]){ //A program that extract the domain name String web="www.thaparedu.url"; String site=web.substring(4,13); System.out.println(site); } } |
Re: Python 3: Exercises And Solutions. by Etinosa1234: 8:25pm On Jul 14, 2020 |
jayphe:package com.Package; import java.util.Scanner; public class AnoExe { public static void main(String args[]){ Scanner word=new Scanner(System.in); System.out.println("How do u feel today" String reply=word.nextLine(); String replyunder=reply.replace(" ","_" System.out.println(replyunder); } } |
Re: Python 3: Exercises And Solutions. by Etinosa1234: 8:30pm On Jul 14, 2020 |
jayphe:I don't think looping is needed here com.Package; import java.util.Scanner; public class Student { public static void main(String args[]){ Scanner res=new Scanner(System.in); System.out.println("What's your name" String name=res.nextLine(); System.out.println("Matric number" String Matric=res.nextLine(); System.out.println("What's your course" String course=res.nextLine(); System.out.println("What is ur score" int score=res.nextInt(); if (score > 95){ System.out.println("U got an A" }else if (score < 94&& score >85) { System.out.println("U got a B" }else if(score <84&& score>75) { System.out.println("U got a C" }else { System.out.println("U tried ur best" } System.out.println("Dear "+name+ " The course u did "+course+" resulted in the "+score+ " %score " } } |
Re: Python 3: Exercises And Solutions. by Etinosa1234: 8:33pm On Jul 14, 2020 |
jayphe: package com.Package; import java.util.Scanner; public class EvenNum { public static void main(String args []){ //to check for an even numbee Scanner word=new Scanner(System.in); System.out.println("Input a number from 100-1000" int num=word.nextInt(); int res=num%2; if (res == 1){ System.out.println("It is an odd number" }else{ System.out.println("It is an even number " } } } |
Re: Python 3: Exercises And Solutions. by Vecto(m): 2:43pm On Aug 26, 2021 |
yo what's the code for this? Write a program that displays the number of seconds in a week. |
(1) (2) (3) (4) (5) (6) (Reply)
Kehinde Adeyemi Among 12 Best Global IT Developers / Mobile Phone Apps For Nigeria / Why Is Programming Difficult?
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 54 |