-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
167 lines (106 loc) · 2.6 KB
/
app.py
File metadata and controls
167 lines (106 loc) · 2.6 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
x = 'Awesome'
def myfunc():
global x
x = 'Fantastic'
print(x)
myfunc()
print(x)
age = 36
txt = "My name is John, I am ", age
print(txt)
my_string = "hello"
print(my_string[0])
print('a' < 'b')
print('ab' > 'aa')
print('a' == 'A')
print(ord('a'))
print(ord('A'))
temperature = 9
if temperature > 30:
print("It's warm outside. You should drink water.")
elif temperature >= 20:
print("It's nice")
else:
print("It's cold")
print("Done")
age = 18
message = "Eligible" if age >= 18 else "Not Eligible" # Ternary Operator
print(message)
if age >= 18 and age < 65:
print("Eligible")
if 18 <= age < 65: # Chaining Comparison Operator, Thats how we write in maths
print("Eligible")
for x in range(1, 10, 3):
print("Hello World", x)
successful = False
for number in range(1, 4):
print("Attempt")
if successful:
print("Successful")
break
else:
print("False")
else:
print("Failed")
for z in range(5):
for y in range(3):
print(f"{z},{y}")
count = 0
for x in range(1, 10):
if x % 2 == 0:
count += 1
print(x, count)
print(f"We have {count} even numbers")
# function that perform specific task
def greet(first, last):
print(f"My name is {first} {last}")
greet("Hassam", "Umer")
# function that returns any value
def greetName(first, last):
return f"Hi! My name is {first} {last}"
message = greetName("John", "Smith")
print(message)
# By default function return None (absence of value)
def alpha():
print("Joy Land")
print(alpha())
# key argument
def sum(k, l):
return k+l
print(sum(k=2, l=7))
# default parameter
def sum(k=8, l=9):
return k+l
print(sum())
# xargs
def multiply(*numbers):
total = 1
for num in numbers:
total *= num
return total
print("Start")
print(multiply(2, 3, 4, 5, 7))
# xxargs
def saveUser(**user):
print(user["id"], user["name"])
saveUser(id=5, name="John", age=56)
def fizzBuzz(input):
if input % 3 == 0 and input % 5 == 0:
print("Fizz Buzz")
elif input % 3 == 0:
print("Fizz")
elif input % 5 == 0:
print("Buzz")
else:
print(input)
fizzBuzz(8)
z = (1, "2", 3, False, (2, 2, 2), [1, 2, 2])
x = (1, "2", 3, False, (2, 2, 2), [1, 2, 2])
print(z is x)
char = list("Hello World")
print(char)
letters = ["a", "b", "c", "d"]
letters[0] = "A"
print(letters[0:3])
print(letters[:]) # copy of original list
print(letters[::-1])