File tree 5 files changed +108
-0
lines changed
5 files changed +108
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Higher Lower Game V2 with HTML
2
+
3
+ <img src = ' https://user-images.githubusercontent.com/65078610/111022737-a1876600-83fa-11eb-8352-85df97470cb2.gif ' width =" 600 " >
Original file line number Diff line number Diff line change
1
+ # Advanced decorators with *args & **kwargs
2
+ class User :
3
+
4
+ def __init__ (self ,username ):
5
+ self .name = username
6
+ self .is_logged_in = False
7
+
8
+ def is_authenticated_decorator (function ):
9
+ def wrapper_function (* args ,** kwargs ):
10
+ if (args [0 ].is_logged_in ):
11
+ function (args [0 ])
12
+ return wrapper_function
13
+
14
+ @is_authenticated_decorator
15
+ def create_blog_post (user ):
16
+ print (f"Welcome to { user .name } 's new blog post!" )
17
+
18
+ new_user = User ("Abhijeet" )
19
+ new_user .is_logged_in = True
20
+ create_blog_post (new_user )
Original file line number Diff line number Diff line change
1
+ # Create a logging_decorator() which is going to log the name of the function that was called,
2
+ # the arguments it was given and finally the returned output.
3
+ def logging_decorator (function ):
4
+ def wrapper (* args ):
5
+ print (f'You called { function .__name__ } { args } ' )
6
+ result = function (* args )
7
+ print (f'It returned: { result } ' )
8
+ return wrapper
9
+
10
+ @logging_decorator
11
+ def add (a ,b ,c ):
12
+ return (a + b + c )
13
+
14
+ add (1 ,2 ,3 )
Original file line number Diff line number Diff line change
1
+ from flask import Flask
2
+
3
+ app = Flask (__name__ )
4
+
5
+ @app .route ("/" )
6
+ def hello ():
7
+ return '<h1 style="text-align:center">Hello World</h1>' \
8
+ '<img src="https://media.giphy.com/media/z3piokwf0WPH81MOhu/giphy.gif" width=200px>' \
9
+ '</div>'
10
+
11
+ def make_bold (function ):
12
+ def wrapper_function ():
13
+ return f'<b>{ function ()} </b>'
14
+ return wrapper_function
15
+
16
+ def make_emphasis (function ):
17
+ def wrapper_function ():
18
+ return f'<i>{ function ()} </i>'
19
+ return wrapper_function
20
+
21
+ def make_underline (function ):
22
+ def wrapper_function ():
23
+ return f'<u>{ function ()} </u>'
24
+ return wrapper_function
25
+
26
+ @app .route ("/bye" )
27
+ @make_bold
28
+ @make_emphasis
29
+ @make_underline
30
+ def bye ():
31
+ return "Bye!"
32
+
33
+ @app .route ("/username/<name>/<int:number>" )
34
+ def greet (name ,number ):
35
+ return f"Hello { name } , you're { number } years old."
36
+
37
+ if __name__ == "__main__" :
38
+ app .run (debug = True )
Original file line number Diff line number Diff line change
1
+ from flask import Flask
2
+ import random
3
+
4
+ app = Flask (__name__ )
5
+
6
+ @app .route ("/" )
7
+ def index ():
8
+ return '<h1 style="text-align:center">Guess a number between 0 and 9</h1>' \
9
+ '<img src="https://media.giphy.com/media/3o7aCSPqXE5C6T8tBC/giphy.gif" width=500 style="display:block; margin:auto">'
10
+
11
+ actual_number = random .randint (1 ,9 )
12
+ print (f"Shhh! Answer is { actual_number } " )
13
+
14
+ @app .route ("/<int:guess>" )
15
+ def game (guess ):
16
+ if guess == actual_number :
17
+ message = 'You found me!'
18
+ color = 'green'
19
+ url = 'https://media.giphy.com/media/4T7e4DmcrP9du/giphy.gif'
20
+ elif guess > actual_number :
21
+ message = 'Too high, try again!'
22
+ color = 'purple'
23
+ url = 'https://media.giphy.com/media/3o6ZtaO9BZHcOjmErm/giphy.gif'
24
+ else :
25
+ message = 'Too low, try again!'
26
+ color = 'tomato'
27
+ url = 'https://media.giphy.com/media/jD4DwBtqPXRXa/giphy.gif'
28
+
29
+ return f'<h1 style="text-align:center; color:{ color } ">{ message } </h1>' \
30
+ f'<img src="{ url } " width=400 style="display:block; margin:auto">'
31
+
32
+ if __name__ == '__main__' :
33
+ app .run (debug = True )
You can’t perform that action at this time.
0 commit comments