Docsity

Python Fundamentals for Computer science, Study Guides, Projects, Research of Computer Science

Toggle sidebar
bg1
🐍
PYTHON CODING — BEGINNER LECTURE NOTES
From Zero to Writing Your First Programs
📚
LESSON 1 — What Is Python?
1. What is Programming?
1. Add the numbers.
2. Divide the result by 3.
3. Show the answer.
🐍
2. What Is Python?
⭐
Why Is Python So Popular?
🌐
Web development
Programming is the process of giving a computer instructions to perform a task.
Imagine telling a person:
"Calculate the average of these three numbers."
You could say:
A computer needs the same kind of instructions, except we write them in a
programming language.
Python is one of those languages.
Python is a high-level programming language designed to be relatively easy for humans
to read and write.
Example:
print("Hello, world!")
The computer displays:
Hello, world!
That's your first Python program.
🎉
Python is used for many things:
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Python Fundamentals for Computer science and more Study Guides, Projects, Research Computer Science in PDF only on Docsity!

🐍 PYTHON CODING — BEGINNER LECTURE NOTES

From Zero to Writing Your First Programs

📚 LESSON 1 — What Is Python?

1. What is Programming?

1. Add the numbers.

2. Divide the result by 3.

3. Show the answer.

🐍 2. What Is Python?

⭐ Why Is Python So Popular?

🌐 Web development

Programming is the process of giving a computer instructions to perform a task.

Imagine telling a person:

"Calculate the average of these three numbers."

You could say:

A computer needs the same kind of instructions, except we write them in a

programming language.

Python is one of those languages.

Python is a high-level programming language designed to be relatively easy for humans

to read and write.

Example:

print("Hello, world!")

The computer displays:

Hello, world!

That's your first Python program. 🎉

Python is used for many things:

🤖 Artificial intelligence

🧠 Machine learning

📊 Data analysis

🔬 Scientific computing

🎮 Game development

⚙ Automation

🔐 Cybersecurity

📱 Software development

📚 LESSON 2 — Your First Python Program

One reason beginners like Python is its relatively simple syntax.

Compare this:

print("Hello!")

to the much more complicated syntax some other languages require.

Python lets you focus more on solving the problem and less on complicated syntax.

The most basic Python instruction is:

print()

It tells Python to display something.

Example:

print("Hello!")

Output:

Hello!

You can print numbers too:

print(25)

Output:

You can also perform calculations:

🔢 Different Types of Data

Integer

Float

String

Boolean

We can change it:

age = 17 print(age)

Output:

Python can store different kinds of information.

Whole numbers:

age = 16

Numbers with decimals:

height = 1.

Text:

name = "Raffa"

True or false:

is_student = True

So we can have:

name = "Raffa" age = 16 height = 1. is_student = True

📝 LESSON 4 — Getting Information From the User

⚠ A VERY IMPORTANT CONCEPT

Programs become much more interesting when users can interact with them.

Python provides:

input()

Example:

name = input("What is your name? ") print("Hello", name)

If the user enters:

Raffa

the program produces:

Hello Raffa

Now you've created an interactive program.

input() normally gives you text , even when the user enters a number.

For example:

age = input("How old are you? ")

The value is treated as a string.

If you want to convert it to an integer:

age = int(input("How old are you? "))

Now Python can perform arithmetic with it.

Example:

age = int(input("How old are you? "))

next_year = age + 1

print("Next year you will be", next_year)

Remainder

🤔 LESSON 6 — Conditional Statements

🔀 If and Else

[ 2^3=8 ]

Result:

because 10 divided by 3 leaves a remainder of 1.

Now we're getting into program logic.

Imagine you're creating a program that checks whether someone can enter a

competition.

You could tell Python:

If the person's age is at least 18, allow them to enter.

Python:

age = 20

if age >= 18: print("You can enter.")

The if statement means:

Only execute this code if the condition is true.

What if the condition isn't true?

Use:

else

Example:

age = 15

if age >= 18:

🔎 Comparison Operators

print("You can enter.") else: print("You cannot enter.")

Output:

You cannot enter.

Python can compare values.

means equal to.

means not equal to.

greater than.

less than.

greater than or equal to.

less than or equal to.

Example:

score = 85

if score >= 75: print("Passed!") else: print("Try again.")

📦 LESSON 8 — Lists

print(number) number += 1

Output:

The line:

number += 1

increases the number by one each time.

A list allows you to store multiple values.

Example:

fruits = ["apple", "banana", "mango"]

You can access individual items.

Python starts counting from 0.

So:

fruits[0]

gives:

apple

and:

fruits[1]

gives:

banana

This can seem weird at first.

🧰 LESSON 9 — Functions

🎯 Functions With Parameters

🔙 Returning Values

Why doesn't Python start at 1?

Because Python uses zero-based indexing.

Suppose you're repeatedly performing the same task.

Instead of writing the same code repeatedly, you can create a function.

Example:

def greet(): print("Hello!")

Now we can call it:

greet()

Output:

Hello!

Functions can receive information.

def greet(name): print("Hello", name)

Then:

greet("Raffa")

Output:

Hello Raffa

Here, name is called a parameter.

Functions can also calculate something and return the result.

Variables

Input

Data types

Conversion

Conditions

Output

🚀 YOUR FIRST PROJECT

🔢 Number Guessing Game

Multiple attempts

Hints

A score system

Random numbers

Difficulty levels

Enter your name: [your name] Enter your score: 87

Student: [your name] Score: 87. Result: Passed

Congratulations. 🎉

You've combined:

into one working program.

Here's a beginner project:

secret = 7

guess = int(input("Guess the number: "))

if guess == secret: print("Correct! 🎉") else: print("Wrong! Try again.")

You can improve it by adding:

🧠 THE PYTHON LEARNING ROADMAP

🟢 LEVEL 1 — Beginner

1. What is programming?

2. Installing/using Python

3. print()

4. Variables

5. Data types

6. Operators

7. User input

8. if / elif / else

9. Loops

10. Lists

🟡 LEVEL 2 — Intermediate

11. Functions

12. Dictionaries

13. Tuples and sets

14. Error handling

15. File handling

16. Modules

17. Object-oriented programming

18. Debugging

19. Working with APIs

20. Virtual environments

🔴 LEVEL 3 — Real-World Python

21. Automation

22. Data analysis

23. Web scraping

24. Building applications

25. Working with databases

26. APIs

Eventually, you'll have a real little game.

If you're turning this into a paid course , I recommend organizing it like this: