Skip to content

zingpython/Intro_python_1

Repository files navigation

Intro_python_1

Practical introduction to Python programming #1

Hi everyone,

This is readme file for a Practical introduction to Python programming #1 workshop.

Here are ten exercises, do them in enclosed python files and push back to Intro_python_1 repo.

Do not forget to create a new branch, DO NOT push to master.

------- Exercises ------

Mailing Address. Create a program that displays your name and complete mailing address formatted in the manner that you would usually see it on the outside of an envelope. Your program does not need to read any input from the user.

Area of a Room. Write a program that asks the user to enter the width and length of a room. Once the values have been read, your program should compute and display the area of the room. The length and the width will be entered as floating point numbers. Include units in your prompt and output message; either feet or meters, depending on which unit you are more comfortable working with.

Bottle Deposits. In many jurisdictions a small deposit is added to drink containers to encourage people to recycle them. In one particular jurisdiction, drink containers holding one liter or less have a $0.10 deposit, and drink containers holding more than one liter have a $0.25 deposit. Write a program that reads the number of containers of each size from the user. Your program should continue by computing and displaying the refund that will be received for returning those containers. Format the output so that it includes a dollar sign and always displays exactly two decimal places.

Tax and Tip. The program that you create for this exercise will begin by reading the cost of a meal ordered at a restaurant from the user. Then your program will compute the tax and tip for the meal. Use your local tax rate when computing the amount of tax owing. Compute the tip as 18 percent of the meal amount (without the tax). The output from your program should include the tax amount, the tip amount, and the grand total for the meal including both the tax and the tip. Format the output so that all of the values are displayed using two decimal places.

Compound Interest. Pretend that you have just opened a new savings account that earns 4 percent interest per year. The interest that you earn is paid at the end of the year, and is added to the balance of the savings account. Write a program that begins by reading the amount of money deposited into the account from the user. Then your program should compute and display the amount in the savings account after 1, 2, and 3 years. Display each amount so that it is rounded to 2 decimal places.

Arithmetic. Create a program that reads two integers, a and b, from the user. Your program should compute and display: • Thesumofaandb • The difference when b is subtracted from a • The product of a and b Exercise 8: Widgets and Gizmos 6 1 Introduction to Programming Exercises • The quotient when a is divided by b • The remainder when a is divided by b • The result of log10 a • The result of ab Hint: You will probably find the log10 function in the math module helpful for computing the second last item in the list.

Units of Time. Create a program that reads a duration from the user as a number of days, hours, minutes, and seconds. Compute and display the total number of seconds represented by this duration.

Units of Time (Again). In this exercise you will reverse the process described in the previous exercise. Develop a program that begins by reading a number of seconds from the user. Then your program should display the equivalent amount of time in the form D:HH:MM:SS, where D, HH, MM, and SS represent days, hours, minutes and sec- onds respectively. The hours, minutes and seconds should all be formatted so that they occupy exactly two digits, with a leading 0 displayed if necessary.

Vowel or Consonant. In this exercise you will create a program that reads a letter of the alphabet from the user. If the user enters a, e, i, o or u then your program should display a message indicating that the entered letter is a vowel. If the user enters y then your program should display a message indicating that sometimes y is a vowel, and sometimes y is a consonant. Otherwise your program should display a message indicating that the letter is a consonant.

Month Name to Number of Days. The length of a month varies from 28 to 31 days. In this exercise you will create a program that reads the name of a month from the user as a string. Then your program should display the number of days in that month. Display “28 or 29 days” for February so that leap years are addressed.

About

Practical introduction to Python programming #1

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages