Re: [Tutor] Help With Python Tasks

2017-09-05 Thread Alan Gauld via Tutor
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


[Tutor] Help With Python Tasks

2017-09-05 Thread Ruth Hardy
Dear Sir or Madam 

I was wondering if you can help me please with these computer science tasks as 
I don’t know where to start:

First Task

Write code do the following things involving strings.  Wherever possible, you 
should try to incorporate functions/procedures, although they are not 
appropriate for all tasks.

Print a list of 20 random numbers one after the other vertically on the screen. 
 Half way through, use a user input request to pause printing until input is 
received.

Ask a user to enter two numbers, one after the other.  Your code should 
validate that you receive numbers and prompt the user appropriately.  For the:

first number, use try-except to ensure you have a floating point number; place 
a comment in you code about how this works
second number, use .isnumeric() to check you have an integer; place a comment 
in your code to explain why this only works for integers
Use a forced type conversion to turn both numbers into floats, divided one by 
the other and print the answer to 2 d.p.  You code should keep on asking for 
numbers until two have been received.

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



Second Task 

Write a menu system based on functions where the main program loop is only 2 
lines long

Write a simple calculator program based around a menu loop.  You should be able 
to enter ‘number 1’ and ‘number 2’ which will be displayed on the screen every 
time the menu is redisplayed’; there should also be a clear screen function 
used to avoid the screen getting too cluttered.

The calculator menu should allow the user to:

enter values for ‘number 1’ and ‘number 2’
add ‘number 1’ and ‘number 2’
subtract ‘number 2’ from ‘number 1’
multiply ‘number 1’ and ‘number 2’
divide ‘number 1’ by ‘number 2’
exit cleanly 
You program must display an answer that the user can read after each 
calculation.


I would appreciate your help so much as I need to have a finished copy  of this 
code by tomorrow late morning !

Kind Regards 
Miss Hardy 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor