-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest1.py
More file actions
63 lines (48 loc) · 1.03 KB
/
Copy pathtest1.py
File metadata and controls
63 lines (48 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
print("=== Python Interpreter Test ===")
# Variables and arithmetic
a = 10
b = 3
print("a =", a)
print("b =", b)
print("a + b =", a + b)
print("a - b =", a - b)
print("a * b =", a * b)
print("a / b =", a / b)
# Strings
name = "Python"
print("Hello " + name)
# Conditionals
if a > b:
print("a is greater than b")
else:
print("a is not greater than b")
# Loop
sum = 0
i = 1
while i <= 5:
sum = sum + i
i = i + 1
print("Sum 1..5 =", sum)
# Function
def square(x):
return x * x
print("square(7) =", square(7))
# Recursion
def factorial(n):
if n <= 1:
return 1
return n * factorial(n - 1)
print("factorial(5) =", factorial(5))
# List
numbers = [1, 2, 3, 4, 5]
print("List length =", len(numbers))
print("First item =", numbers[0])
print("Last item =", numbers[4])
i = 0
while i < len(numbers):
print("numbers[", i, "] =", numbers[i])
i = i + 1
# Boolean logic
flag = (a > 5) and (b < 5)
print("flag =", flag)
print("=== Test Complete ===")