Skip to content

Commit 6ee7208

Browse files
committed
add python lesson and its challenges
0 parents  commit 6ee7208

2 files changed

Lines changed: 102 additions & 0 deletions

File tree

Python/lesson1/lesson1.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#Variables declaration
2+
name = "Marcus"
3+
age = 20
4+
height = 5.9
5+
is_student = True
6+
7+
#String— Text data:
8+
first_name = "Marcus"
9+
last_name = 'Aurelius' # single or double quotes both work
10+
full_name = first_name + " " + last_name # joining strings is called concatenation
11+
print(full_name) # Output: Marcus Aurelius
12+
13+
#Integer — whole numbers:
14+
15+
age = 25
16+
year = 2025
17+
score = -10
18+
print(age + 5) # Output: 30
19+
print(year - 36)
20+
print("My score is: ", score)
21+
22+
#float — decimal numbers
23+
gpa = 3.75
24+
price = 9.99
25+
pi = 3.14159
26+
27+
#Boolean — True or False only
28+
is_logged_in = True
29+
has_permission = False
30+
# Industry note: Booleans power almost every decision in programming
31+
32+
#Nonetype The absence of value
33+
result = None
34+
# Used when a variable exists but has no value yet
35+
print(result)
36+
37+
#Checking and converting data type:
38+
name = "Marcus"
39+
age = 20
40+
gpa = 3.5
41+
42+
# Check what type a variable is
43+
print(type(name)) # <class 'str'>
44+
print(type(age)) # <class 'int'>
45+
print(type(gpa)) # <class 'float'>
46+
47+
# Convert between types (called Type Casting)
48+
age_as_string = str(age) # "20"
49+
gpa_as_int = int(gpa) # 3 (drops the decimal, doesn't round)
50+
number = float("3.14") # 3.14
51+
52+
#Taking input from the user:
53+
54+
name = input("What is your name? ")
55+
print("Hello, " + name + "!")
56+
57+
#⚠️ Important: input() always returns a string, even if the user types a number. So do this when you need a number:
58+
59+
age = int(input("How old are you? "))
60+
print("In 10 years you'll be", age + 10)
61+
62+
#f-Strings — The Industry Standard Way to Format Output
63+
name = "Marcus"
64+
age = 20
65+
print(f"Hello {name}, you are {age} years old.")
66+
# Output: Hello Marcus, you are 20 years old.
67+
68+
#Lesson1 Summary:
69+
# Lesson 1 - Variables & Data Types
70+
# Store user info
71+
name = input("Enter your name: ")
72+
age = int(input("Enter your age: "))
73+
city = input("What city are you from? ")
74+
75+
# Calculate
76+
birth_year = 2025 - age
77+
78+
# Display using f-strings
79+
print(f"Name : {name}")
80+
print(f"Age : {age}")
81+
print(f"City : {city}")
82+
print(f"Born in : {birth_year}")
83+
print(f"Adult? : {age >= 18}")

Python/lesson1/lesson_Challenge.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Store user information
2+
product_name = input("What's the product name? ")
3+
price = float(input("What's the price? "))
4+
quantity = int(input("What's the quantity bought? "))
5+
6+
# Calculations
7+
total_cost = round(price * quantity, 2)
8+
tax = round(total_cost * 0.075, 2) # 7.5% tax
9+
final_price = round(total_cost + tax, 2) # original total + tax
10+
11+
# Displaying the receipt
12+
print("********* Receipt *********")
13+
print(f"Product Name : {product_name}")
14+
print(f"Price : ₦{price}")
15+
print(f"Quantity : {quantity}")
16+
print(f"Total Cost : ₦{total_cost}")
17+
print(f"Tax (7.5%) : ₦{tax}")
18+
print(f"Final Price : ₦{final_price}")
19+
print("***************************")

0 commit comments

Comments
 (0)