0% found this document useful (0 votes)
0 views

Python1

Python is a high-level programming language known for its simplicity and versatility, used in various fields such as web development, data analysis, and artificial intelligence. Key concepts include variables, user input, conditional statements (if, else, elif), and loops (while, for), which are essential for creating interactive programs. The document also outlines practical coding exercises to reinforce understanding of Python fundamentals.

Uploaded by

Nathania Dsouza
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Python1

Python is a high-level programming language known for its simplicity and versatility, used in various fields such as web development, data analysis, and artificial intelligence. Key concepts include variables, user input, conditional statements (if, else, elif), and loops (while, for), which are essential for creating interactive programs. The document also outlines practical coding exercises to reinforce understanding of Python fundamentals.

Uploaded by

Nathania Dsouza
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 23

Python –

Computer
programming

Revision
What is python and why is it used in
computing?
Python is a high-level, interpreted programming language known for its simplicity and readability.
It is used in computing because it supports multiple programming paradigms, has a vast
ecosystem of libraries, and allows rapid development for applications like web development, data
science, automation, and artificial intelligence.
How can python be used in the
real world?
Python is used in the real world for web development, data analysis, automation,
artificial intelligence, and scientific computing. It powers applications like websites,
financial modeling, robotics, and machine learning systems.
Printing without a
variable
To print text directly without using a variable, you
need to enclose the text in quotation marks ("" or '')
inside the print() function.
Printing with a
variable
To print text using a variable in Python, you first
need to define the variable and then use the print()
function to display its value.
🤔How can we let users enter their own information?
✅ Use the input() function.

User Input in
Python

Key Takeaways
🔹 Variables store different types of data.
🔹 input() allows users to enter their own details.
🔹 Use int() to convert user input into a number when
needed.
Key points What is float in Python?
In Python, a float (short for "floating-point number") is a
number with a decimal point. It is used to represent
real numbers, including fractions and decimal values.
Variables and float
and input
The formula number 1 = float(input("number 1: ")) is a
Python code snippet. Here's what each part of it does:
•input("number 1: "): This prompts the user to enter a
value. The string "number 1: " is shown as a message
in the terminal, asking the user for input.
•float(): This function converts the input value to a
floating-point number. So, if the user enters something
like "3.14", it will be converted to the float 3.14.
•number 1 =: This assigns the converted value to the
variable number 1. This variable will now store the
floating-point number entered by the user.
In summary, this code takes user input, converts it into
a float, and stores it in a variable named number 1.
If statements
What is an if statement?
An if statement is like a question you ask in your
code. It checks if something is true or not. If it's true,
it does one thing. If it's not true, it can do something
else.

Here’s what happens:


•The program checks if the weather is sunny.
•If it is sunny, it says: “Go outside and play!”
•If it’s not sunny, nothing happens (because there's no else yet).
Else statements
What is an else statement?
An else statement is like saying, “If it’s not sunny,
then I will do something else.” It comes after the if
statement.

Now, the program checks:


•If the weather is sunny, it will say “Go outside and play!”
•If it’s not sunny (like when it’s rainy), it will say “Stay inside
and read a book!”
What The .lower() method in Python is used to convert all
the letters in a string to lowercase. This is helpful
when you want to make sure that the text is all in

is .lower() lowercase, which can help when comparing words or


checking if something is equal regardless of whether
it's typed in uppercase or lowercase.
Int in python In Python, the int() function is used to
convert a value into an integer. An
integer is a whole number (positive,
negative, or zero) without any decimal
point.
Statements
In Python, the hashtag (#) is used to add comments to your code.

Statements # Comments are lines of text that are not executed by the Python
interpreter. They're meant for humans to read and understand the
code better.
Purpose of Comments:

Explain Code: Comments help explain what a part of the code


does, making it easier for others (or yourself) to understand it later.

Make Code Readable: Comments make your code more readable


by describing the logic behind complex parts of the code.

Prevent Code from Running: You can use comments to


temporarily "disable" parts of the code without deleting them, which
can be helpful for debugging.
Elif statements
In Python, elif stands for "else if", and it's used to check multiple
conditions in an if statement. It allows you to test several
conditions one by one, and the first condition that is true will
execute its corresponding block of code. If none of the if or elif
conditions are true, the else block (if present) will be executed.
A certain condition or rule that must be
Conditional met before an action is performed
Tell a computer WHEN to perform a
statements certain task
Follows one of these formats
IF (condition is met), THEN (action
performed)
IF (condition is met), THEN (action
performed), ELSE (different action
performed)
Creating a while while loop: Runs as long as a
specified condition is true.
loop
Key Words 1.
2.
Python: A popular programming language, platform for coding
Input: Function which requests the user to put information
3. Variable: It's a container which stores values which can be changed
4. Conditional statements: Statements such as if, else, elif in your
program. It checks whether or not a condition is met.
5. Loops: Repetetion of something
6. Logical operator (and, or, not): and – two conditions are met, or- one
condition is met, not- neither of the conditions are met
7. Integer: Whole numbers are integers
8. Float: Decimals
9. String: String refers to words, characters or texts you have typed in
10. List:
11. Boolean: True or False statements
12. Print: Print function displays whatever you type in between ("")
13. Range: Function that returns a few different numbers
14. If: To see if a condition is met (conditional statement)
15. Else: Else looks at the final option for the condition to be met
(conditional statement)
16. Elif: If the first condition is not met. It finds out another condition/option.
(conditional statement)
17. For loop:For loop is a statement that you repeat over a sequence. You
choose the amount of time you want something to repeat
18. While loop: A loop that doesn't stop until a specific condition is met.
Programmes
Practice the following codes:
1. Print your name and age

2. Create a program that allows the user to input their name and age

3. Create a program that asks for 2 numbers and add them.

4. Create a program that that asks for 5 numbers and multiply them

5. Create a program that asks the user to specify their favorite color. If the colour is equal to

"red", increase the red_count by 1


6. Write a program that uses a while loop to ask eight people their age. After collecting all

ages, calculate and print the average age.


7. Create a program that uses a while loop to ask six people about their favourite hobby. If the

hobby is "reading", increment a counter. At the end, display how many people like reading.
8. Use a while loop to ask 10 people which school subject they like the most. Keep a running

tally for each subject (e.g., "Maths", "Science"). At the end, print the most popular subject.

You might also like