- Access exercises (91)
- C# exercises (79)
- Excel exercises (278)
- Power Apps exercises (13)
- Power Automate exercises (18)
- Power BI exercises (139)
- Power Platform exercises (157)
- Python exercises (28)
- Report Builder exercises (141)
- SQL exercises (198)
- SSAS exercises (51)
- SSIS exercises (46)
- SSRS exercises (99)
- VBA exercises (85)
- Visual Basic exercises (46)
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.
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 life.py, 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:
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:
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.