1 / 16

Python Number Manipulation - Learning to Store and Calculate Numbers

This lesson covers the basics of working with numbers in Python, including storing numbers, performing mathematical operations, and using input commands. Students will learn about the difference between integers and floats and how to convert between them. The lesson includes practical exercises and a recap of key concepts.

rtune
Télécharger la présentation

Python Number Manipulation - Learning to Store and Calculate Numbers

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Bell work str chr print 1. What is the name of the programming language that we started to learn last lesson? 2. Which of these commands did we learn last lesson: ord float input int

  2. Objectives To be able to write a program that works with inputs and numbers.

  3. Starter We are learning to use Python. Open the starter from the lesson 2 folder and drag the pieces of code into the correct order..

  4. Starter - answers

  5. Task 1 – working with numbers in Python Open PyScripter… If you type in a sum then Python can do the maths for you. Try these sums – what happens? print(3+3) print(4*25) print(10/5) print(2-10)

  6. Task 1a – storing numbers Last week we used the input command to ask the user to enter data. We’re going to use this again to work with numbers. What do you think this code will do? Type this in: numberOne = input(“Enter a number between 0 and 10 ") numberTwo = input(“Enter a number between 0 and 10 ") print (numberOne + numberTwo) Press the RUN icon. What happened and why do you think it happened?

  7. Task 1a – storing numbers You should have seen this in the compiler window. It doesn’t add the two numbers together because Python thinks you are inputting text unless we tell it otherwise.

  8. Task 1b – storing numbers Change what you just typed in to this numberOne = input(“Enter your name") numberTwo = input(“Enter a friend’s name") print (numberOne + numberTwo) Press the RUN icon. What happened and why do you think it happened?

  9. Task 1b – storing numbers You should have seen the two names joined together. What does this mean?

  10. Task 2a – storing numbers Last week we used the input command to ask the user to enter data. We’re going to use this again to work with numbers. What do you think this code will do? Type this in: numberOne = int(input(“Enter a number between 0 and 10 ")) numberTwo = int(input(“Enter a number between 0 and 10 ")) print (numberOne + numberTwo) Press the RUN icon. What happened and why do you think it happened?

  11. Task 2a – storing numbers I typed in 5 and 5 with this code and now it added them together. What does int do? What happens if you type in 1.5 and 5.5 as your numbers when Python asks you to enter them?

  12. Task 2b – storing numbers We know from the last slide that int will not allow us to type in decimal numbers. Let’s change our code and replace int with float. Type this in: numberOne = float(input(“Enter a no. between 0 and 10 ")) numberTwo = float(input(“Enter a no. between 0 and 10 ")) print (numberOne + numberTwo) Press the RUN icon. Type in 2 and 5.5 as your numbers when it asks you to enter data.

  13. Task 2b – storing numbers I typed in 2 and 5.5 with this code and now it added decimal numbers together. What is the difference between int and float?

  14. RECAP! RECAP! RECAP! What does this button do? What do these do? Why would we change int to float?

  15. In your booklets… Complete the task on page 7 of your booklet – build a calorie counter.

  16. 1. What 2 commands have we used to store numbers today? 2. What command do you type in to get the user to input a number? 3. What is the variable in this: StudentName = input(“Enter name”) 4. What is wrong with this statement: X = input(int(“Please enter a number”) 5. Is a decimal or whole number stored in an int? 6. Is a decimal or whole number stored in a float? Plenary

More Related