Skip to content

Commit 50dff54

Browse files
Add 4 basic Python practice files (variables, types, input/output, conditionals/loops)
1 parent c6ace28 commit 50dff54

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed

01_basics/conditionals_loops.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Conditional statement
2+
num = int(input("Enter a number: "))
3+
if num > 0:
4+
print("Positive number")
5+
elif num == 0:
6+
print("Zero")
7+
else:
8+
print("Negative number")
9+
10+
# For loop
11+
print("\nCounting from 1 to 5:")
12+
for i in range(1, 6):
13+
print(i)
14+
15+
# While loop
16+
count = 0
17+
print("\nCounting with while loop:")
18+
while count < 5:
19+
print("Count is", count)
20+
count += 1

01_basics/input_output.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Getting user input
2+
name = input("Enter your name: ")
3+
age = int(input("Enter your age: "))
4+
my_name = "Hugo"
5+
my_age = 22
6+
7+
# Displaying output
8+
print("\nHello", name + " !")
9+
print("\nYou are", age, "years old.")
10+
11+
if my_age == age :
12+
print(f"\nAnd my name is {my_name}, I am {my_age} years old too !")
13+
else :
14+
print(f"\nAnd my name is {my_name}, I am {my_age} years old !")

01_basics/types.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
isType = "is of type"
2+
3+
a = 5
4+
print(a, isType, type(a))
5+
6+
b = 5.6
7+
print(b, isType, type(b))
8+
9+
c = "Hello"
10+
print(c, isType, type(c))
11+
12+
d = True
13+
print(d, isType, type(d))
14+
15+
e = [1, 2, 3]
16+
print(e, isType, type(e))

01_basics/variables.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name = "Hugo"
2+
age = 22
3+
is_student = True
4+
5+
# Displaying variables
6+
print("Name:", name)
7+
print("Age:", age)
8+
print("Student:", is_student)
9+
10+
11+
print(f"{name} is {age} years old and he is student.")

0 commit comments

Comments
 (0)