Skip to content

Latest commit

 

History

History
66 lines (43 loc) · 5.07 KB

README.md

File metadata and controls

66 lines (43 loc) · 5.07 KB

Python-By-Example

Ejercicios del libro 'Python By Example' del autor Nichola Lacey.

Ejercicios

The Basics

Ask for the user’s first name and display the output message Hello [First Name]

Ask for the user’s first name and then ask for their surname and display the output message Hello [First Name] [Surname].

Write code that will display the joke “What do you call a bear with no teeth?” and on the next line display the answer “A gummy bear!” Try to create it using only one line of code.

Ask the user to enter two numbers. Add them together and display the answer as The total is [answer].

Ask the user to enter three numbers. Add together the first two numbers and then multiply this total by the third. Display the answer as The answer is [answer].

Ask how many slices of pizza the user started with and ask how many slices they have eaten. Work out how many slices they have left and display the answer in a userfriendly format.

Ask the user for their name and their age. Add 1 to their age and display the output [Name] next birthday you will be [new age].

Ask for the total price of the bill, then ask how many diners there are. Divide the total bill by the number of diners and show how much each person must pay.

Write a program that will ask for a number of days and then will show how many hours, minutes and seconds are in that number of days.

There are 2,204 pounds in a kilogram. Ask the user to enter a weight in kilograms and convert it to pounds.

Task the user to enter a number over 100 and then enter a number under 10 and tell them how many times the smaller number goes into the larger number in a user-friendly format.

If Statements

Ask for two numbers. If the first one is larger than the second, display the second number firstand then the first number, otherwise show the first number first and then the second.

Ask the user to enter a number that is under 20. If they enter a number that is 20 or more, display the message “Too high”, otherwise display “Thank you”.

Ask the user to enter a number between 10 and 20 (inclusive). If they enter a number within this range, display the message “Thank you”, otherwise display the message “Incorrect answer”.

Ask the user to enter their favourite colour. If they enter “red”, “RED” or “Red” display the message “I like red too”, otherwise display the message “I don’t like [colour], I prefer red”.

Ask the user if it is raining and convert their answer to lower case so it doesn’t matter what case they type it in. If they answer “yes”, ask if it is windy. If they answer “yes” to this second question, display the answer “It is too windy for an umbrella”, otherwise display the message “Take an umbrella”. If they did not answer yes to the first question, display the answer “Enjoy your day”.

Ask the user’s age. If they are 18 or over, display the message “You can vote”, if they are aged 17, display the message “You can learn to drive”, if they are 16, display the message “You can buy a lottery ticket”, if they are under 16, display the message “You can go Trickor- Treating”.

Ask the user to enter a number. If it is under 10, display the message “Too low”, if their number is between 10 and 20, display “Correct”, otherwise display “Too high”.

Ask the user to enter 1, 2 or 3. If they enter a 1, display the message “Thank you”, if they enter a 2, display “Well done”, if they enter a 3, display “Correct”. If they enter anything else, display “Error message”.