-
Notifications
You must be signed in to change notification settings - Fork 0
/
test1.py
68 lines (42 loc) · 899 Bytes
/
test1.py
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
64
65
66
67
# lists and for loops
ls1 = ["e", "t", "y", "b", "r", "u"]
def sample(any_list):
res = []
for i in ls1:
res.append(i + "tu-")
return res
print sample(ls1)
# ---------------------
letters = ['a', 'b', 'c', 'd']
print " ".join(letters)
print "---".join(letters)
# -----------
word = "Marble"
for char in word:
print char,
print ''
#---
def is_even(x):
if x % 2 == 0:
return True
else:
return False
print is_even(6)
# this one sums up all the digits from which the argument consists of. The parameter is int, not string.
def digit_sum(n):
result = 0
for i in str(n):
result += int(i)
return result
n = 1234
print digit_sum(n)
# Factorial ###############
def factorial(x):
result = 1
print range(1, x + 1)
for i in range(1, x + 1):
result *= i
return result
x = 4
print factorial(x)
#