some emoticon tests

This commit is contained in:
waldek 2021-10-27 14:37:39 +02:00
parent 8b24ba9577
commit ee2ebdac59
1 changed files with 47 additions and 3 deletions

View File

@ -120,7 +120,8 @@ print("my name is Wouter")
print("I'm", 35, "years old")
```
__🏃 Try it__
🏃 Try it
---
Try printing different lines and with combinations of different object types such as `int`, `float` and `str`.
What happens if you *add* (`+`) values to one another?
@ -140,7 +141,8 @@ While it works perfectly well it's not super *readable*.
We can improve the readability by using either string replacement or string formatting.
My personal preference is string formatting.
__🏃 Try it__
🏃 Try it
---
Have a look at both ways illustrated below and try them out.
@ -151,7 +153,7 @@ Have a look at both ways illustrated below and try them out.
name = "Wouter"
age = "35"
print("Hello, my name is {name} and I'm {age} years old.")
print(f"Hello, my name is {name} and I'm {age} years old.")
```
## String formatting
@ -191,6 +193,9 @@ The shell is more *verbose* and will explicitly tell you what a function returns
So, functions can **return** something but how can we *use* the returned objects?
This is where **variables** come in handy.
The `input` function will **always** return an object of type `str`.
If we want to use this object later in our code we need to add a *post-it* to it so we can reference it later.
Remember that the object is created by the function call, and we add the reference after the object's creation.
```python3
print("What is your name? ")
@ -198,8 +203,47 @@ answer = input()
print("Well hello", answer, "!")
```
**When looking at the code block above did you notice the *empty space* I added after my question?
Can you tell me why I did that?**
🏃 Try it
---
Try playing around with the `input` function and incorporate the different ways to print with it.
Ask multiple questions and combine the answers to print on one line.
## Functions can take arguments
Some, if not most, functions will take one or more arguments when calling them.
This might sound complicated but you've already done this!
The `print` function takes *a-message-to-print* as an argument, or even multiple ones as you probably noticed when playing around.
The `input` function *can* take arguments but as we've seen does not *require* an argument.
When looking at the documentation we can discover **what** the function does, how to **call** the function and what it **returns**.
⛑ **CTRL-q opens the documentation in pycharm**
```
Help on built-in function input in module builtins:
input(prompt=None, /)
Read a string from standard input. The trailing newline is stripped.
The prompt string, if given, is printed to standard output without a
trailing newline before reading input.
If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError.
On *nix systems, readline is used if available.
```
We can add one **argument** inside the `input` call which serves as a prompt.
Now which `type` should the object we pass to `input` be?
The most logical type would be a `str` that represents the *question* to ask the user no?
Let's try it out.
```python3
```
# Taking input and evaluation
TODO say hello plus ask for age