[Tutor] Python

Alan Gauld alan.gauld at yahoo.co.uk
Thu Nov 30 13:10:39 EST 2017


On 30/11/17 08:20, Jeroen van de Ven wrote:
> Hello,
> Can you build these 4 programms for me?

Nice try.
The answer is yes we can, but no we won't.
You wouldn't learn anything if we did and
this list is here to teach.

That means you need to write the code and
we will offer help and suggestions.

> 1:
> Input: 5 7 (rows and colloms)
> Output:
> *******
> *******
> *******
> *******
> *******

Can you read a line of input and extract 2 numbers?
Can you write a loop that repeats as often as one
of the numbers you read?
Can you write a print statement that outputs as many '*'s as the other
number?
If so, put it together and jobs done.
If not do what you can and show us the result.

> 2:
> Move all of the letters 23 places to the right. All capital letters.
> A B C D E F G H I J K L M N O P Q R S T U V W X Y Z (boodschap)
> X Y Z A B C D E F G H I J K L M N O P Q R S T U V W (code)
> 
> N=23
> 
> Example
> Input:   COMPUTER
> Output: ZLJMRQBO

Read a number.
Shift the letters - this is probably easiest with slicing
and a wee bit of slightly tricky arithmetic
Read the input word
Now use the two lists of letters to map each letter (hint Python has
some string functions that do precisely this.)


> 3: Bitcoin:
> Make as much as possible money.
> -You start with no bitcoin.
> -You stop with no bitcoinJ
> -Never have more then 1 bitcoin at a time.
> -You can sell and buy a bitcoin whenever you want to.
> First input = N, the amount of days. Then the input is the course of the
> bitcoin of every day.
> Output is 1 line with maximum of profit. It can be 0.
> Example:
> Input: 10 5 11 4 2 8 10 7 4 3 6
> Output: 17

Sorry, I know zilch about bitcoin, so don't even understand
the question.

> 
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list