Python1
Python1
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.
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:
2. Create a program that allows the user to input their name and age
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
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.