Python | Basic coding exercise | Create a simple program to add two numbers

This exercise is provided to allow potential course delegates to choose the correct Wise Owl Microsoft training course, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.

You can learn how to do this exercise if you attend the course listed below!

Software ==> Python  (25 exercises)
Version ==> Latest version
Topic ==> Basic coding  (3 exercises)
Level ==> Average difficulty
Classroom ==> Python programming
Online ==> Python programming

You need a minimum screen resolution of about 700 pixels width to see our exercises. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.

Your task for this exercise is to write a program to add together two numbers typed in by a user.  Here's what a typical output from the program might look like:

Adding two numbers

The hard part of this exercise is making sure that you're working with numbers when you need numbers, and text when you need text.

 

To being with, create a new program called Slack adder.py.  Within this create two variables to equal the two inputs typed in by your user.

You'll need to use the int() function to convert the text typed in by your user into integers, otherwise you won't be able to subsequently add the two numbers together.  You can assume that your user will be well-behaved and type in only numbers.

Create a third variable to hold the sum of your two numbers, then print out your results (this time you'll need to use the str() function to turn your numbers back into text, before using the + sign to concatenate the bits of text you need to form your message).

When your program is working to your satisfaction, save it and close it down!

You can unzip this file to see the answers to this exercise, although please remember this is for your personal use only.
This page has 0 threads Add post