On 05/09/17 19:25, Ruth Hardy wrote:

> I was wondering if you can help me please with these computer science tasks

We can help, but we won;t do them for you.

> First Task
> 
> Write code do the following things involving strings.  Wherever possible, 
> you should try to incorporate functions/procedures, 
> 
> Print a list of 20 random numbers one after the other vertically on the 
> screen.

There are (at least) two ways to do this. One very easy but laborious,
the other much shorter and quicker.
Do you know what they are? Can you print 20 numbers (forget random for
now) on the screen?

> Half way through, use a user input request to pause printing until 
> input is received.

Do you know how to read user input?

> Ask a user to enter two numbers, one after the other.  

This is slightly ambiguous, but I'd assume they mean
you should ask for input twice.
Do you know how to store user input into a variable?
Do you know how to convert user input to a number?

> Your code should validate that you receive numbers and 
> prompt the user appropriately.  

Do you know how to validate/check that the received
input is a number? (there are several ways to do this,
I'm not sure how they expect you to tackle it, it depends
on what you've been taught so far)


For the:
> first number, use try-except to ensure you have a floating point number; 

OK, That answers my question. You can use try/except
to check the number is valid...

> place a comment in you code about how this works
> second number, use .isnumeric() to check you have an integer; 

OK, They tell you what to do here.
Personally I don;t like the isnumeric() technique but its
what they want you to do so do it...

> Use a forced type conversion to turn both numbers into floats, >divided one 
> by the other and print the answer to 2 d.p.

Do you know how to print a number so it shows two dp?

> You code should keep on asking for numbers until two have been received.

OK, Lets just get it working for a single pair of numbers first.
Done that? Good, so now wrap it in a loop. What kind of loop will
work here?

> Ask the user to input a true/false value and convert th> input to a Boolean 
> (hint: I don’t think you can do a forced
> type conversion for this…)

The hint is correct.
How would you do it without a type conversion?

> Second Task 

Let's leave this task to another email.

See if you can answer the questions above.
If you can you should be able to join the bits together to get
the task completed. If not come back to us with specific
issues sand we'll explain a bit more.

Show us your code plus any error messages you get.

HTH
-- 
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


_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to