-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathgame_02_comments.py
More file actions
64 lines (55 loc) · 2.28 KB
/
game_02_comments.py
File metadata and controls
64 lines (55 loc) · 2.28 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
def main():
'''
Getting your name using in-built function called input().
Prints the players name.
There will be some editing of the code in this part of the workshop
showing how to declare, assign and call a variable.
'''
## We are going to use raw_input so we can have some interaction
## with player of game
## The " > " is just there for decorations, try using other characters.
## 1 - Getting your name
print(input("What's your name? > "))
## Now run it, after you type your name, it prints it on the next line.
## 1.2 - Refined
##
## Comment out line 15 by putting # where the code the line starts
## Uncomment lines 28 and 35
## player_name is a variable, it is created to store objects
## like strings, numbers.
## Remember to give variables memorable names or else when you
## review your code you don't know what it is used for.
#
#player_name = input("What's your name? >")
## The following is formatted string literal.
## The {} tells Python that there is something to be substituted.
## We are using fstrings to substitute the variable player_name.
## More info: https://docs.python.org/3/whatsnew/3.6.html#pep-498-formatted-string-literals
#
#print(f"Your name is {player_name}")
## Now uncomment line 42
##
## Some neat tricks with string manipulations:-
## This turns your string all to uppercase
#
#print(f"Your name is {player_name.upper()}")
## Open your Python interpreter, try the following
## Remember, in terminal, when you type Python and hit return,
## you should see >>>
##
## >>> player_name = "bob"
## >>> print(f"Your name is {player_name.upper()}")
##
## Try other string built-in functions.
## Find it in Python docs by
## 1) https://www.python.org/
## 2) Click on Docs
## 3) Click on "Library Reference"
## 4) Look for "Text Sequence Type - str" and read up the various
## functions (or methods) and experiment in your Python interpretor.
##
## Don't be afraid to your your Python interpreter, we use it all
## the time to test and try out everything. Most Python code you right,
## you should be able to test in the interpreter.
if __name__ == '__main__':
main()