Python | Basic coding exercise | Ask people for their name and take on the meaning of life

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.

Software ==> Python  (28 exercises)
Version ==> Latest version
Topic ==> Basic coding  (3 exercises)
Level ==> Relatively easy
Subject ==> Python training

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.

For this exercise you are invited to write a program which asks a user for two bits of information:

  • Their name; and
  • What they think is the meaning of life.

The program should then summarise the answers you've received. 

Start by creating a program called The meaning of, and use the input function to get the value of two variables:

Variable name Set to
person_name Your user's name (typed in at the command prompt)
life_meaning Your user's opinion of the meaning of life (again, typed in at the command prompt).

Run your program to test it out:

Program progress

Notice that the second question should incorporate the value of the variable set in answer to the first question (the person's name).

Extend your program to print out a summary of what you've learnt:

Final output

An example final output from your program with questions answered by Bob the nihilist.

Remember that you can include \n in your text to generate a new line.

Test that your program works for optimistics, pessimists and anyone in between, then 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