Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
Python programming
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GGP_python
Python programming
Commits
ab07bccb
Commit
ab07bccb
authored
2 years ago
by
Franziska Niemeyer
Browse files
Options
Downloads
Patches
Plain Diff
Upload solutions for gap_exercise1_basics
parent
d0160d32
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Exercises/solutions/gap_exercise1_basics.ipynb
+463
-0
463 additions, 0 deletions
Exercises/solutions/gap_exercise1_basics.ipynb
with
463 additions
and
0 deletions
Exercises/solutions/gap_exercise1_basics.ipynb
0 → 100644
+
463
−
0
View file @
ab07bccb
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "gaps_exercises1.ipynb",
"provenance": [],
"collapsed_sections": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"source": [
"# Python course - Exercises Gap text"
],
"metadata": {
"id": "kH0p2uT-sQ6y",
"pycharm": {
"name": "#%% md\n"
}
}
},
{
"cell_type": "markdown",
"source": [
"Correct the Code"
],
"metadata": {
"id": "uW9SoYEyrlRL",
"pycharm": {
"name": "#%% md\n"
}
}
},
{
"cell_type": "code",
"source": [
"# What is missing here? Expected output: Hi!\n",
"print('Hi!')"
],
"metadata": {
"id": "Qflb9AWfrykh",
"pycharm": {
"name": "#%%\n"
}
},
"execution_count": 5,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hi!\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"# Here are two mistakes. Can you find them?\n",
"# Hi! I am a comment. How are you?\n",
"print('Hello world!')"
],
"metadata": {
"id": "eemU0jTksxu5",
"pycharm": {
"name": "#%%\n"
}
},
"execution_count": 6,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hello world!\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"# Multi-line comments\n",
"\"\"\"\n",
"I want to be a\n",
"mutli line comment.\n",
"\"\"\" \n",
"print('Hello world!')"
],
"metadata": {
"id": "2ysNg9wDtaZ9",
"pycharm": {
"name": "#%%\n"
}
},
"execution_count": 7,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hello world!\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"# Expected output: 5\n",
"c = 5\n",
"print(c)"
],
"metadata": {
"id": "Vexbuvx1u1NS",
"pycharm": {
"name": "#%%\n"
}
},
"execution_count": 8,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"5\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"# How to print two strings as one. Expected output: Hello world\n",
"a = 'Hello '\n",
"b = 'world'\n",
"print( a + b )"
],
"metadata": {
"id": "cGTJ95-9wzLT",
"pycharm": {
"name": "#%%\n"
}
},
"execution_count": 9,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hello world\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"# Variable types\n",
"# Does the error output help you?\n",
"a = 'Hello'\n",
"b = 0\n",
"print( a + str(b) )"
],
"metadata": {
"id": "6QiU3l2_xFnP",
"pycharm": {
"name": "#%%\n"
}
},
"execution_count": 10,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hello0\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"# What is missing?\n",
"a = 'Hello'\n",
"b = a\n",
"\n",
"if a == b:\n",
" print('Same!')"
],
"metadata": {
"id": "_YtGF9xqzFoR",
"pycharm": {
"name": "#%%\n"
}
},
"execution_count": 11,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Same!\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"# Print the variable type\n",
"# Expected output: a is of type <class 'str'>\n",
"a = 'How are you?'\n",
"print('a is of type', type(a))"
],
"metadata": {
"id": "wH0ifA4czyDV",
"pycharm": {
"name": "#%%\n"
}
},
"execution_count": 12,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"a is of type <class 'str'>\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"# Variable names: What is allowed and what not?\n",
"_1th_string = \"Hello\"\n",
"second_string = 'world'\n",
"third_string = '!'\n",
"FOURTH_STRING = 'How'\n",
"FIFTH_STRING = 'are'\n",
"_6th_string = 'you?'\n",
"\n",
"print(_1th_string, second_string, \n",
" third_string, FOURTH_STRING,\n",
" FIFTH_STRING, _6th_string\n",
" )"
],
"metadata": {
"id": "Spcu5lGc0Uv9",
"pycharm": {
"name": "#%%\n"
}
},
"execution_count": 13,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hello world ! How are you?\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"# convert b into float\n",
"a = 2\n",
"b = float(a)\n",
"print(b)"
],
"metadata": {
"id": "_TcdURMh2yJZ",
"pycharm": {
"name": "#%%\n"
}
},
"execution_count": 14,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2.0\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"# How to access Lists?\n",
"my_list = [\"!\", \"Hello\", 'you', \"How\", '?', 1, 'are', 2, 3, \"world\"]\n",
"print(my_list)\n",
"print(my_list[ 0 ]) # print '!'\n",
"print(my_list[ 1 ]) # print 'Hello'\n",
"print(my_list[ -1 ]) # print the last element of a list without the real index; here 'world'\n",
"### print 'Hello world! How are you?':\n",
"print(my_list[ 1 ], my_list[ -1 ] ,my_list[0] ,my_list[ 3 ] ,my_list[ -4 ] ,my_list[ 2 ], my_list[4])"
],
"metadata": {
"id": "5VripGXYxBf8",
"pycharm": {
"name": "#%%\n"
}
},
"execution_count": 15,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['!', 'Hello', 'you', 'How', '?', 1, 'are', 2, 3, 'world']\n",
"!\n",
"Hello\n",
"world\n",
"Hello world ! How are you ?\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"# Indices of Strings\n",
"a = 'Hello world!'\n",
"print(a[ -1 ]) # only print !\n",
"print(a[ 0 ]) # only print H\n",
"print(a[ 6:-1 ]) # only print 'world', without '!'"
],
"metadata": {
"id": "V3VJP2gg1HLT",
"pycharm": {
"name": "#%%\n"
}
},
"execution_count": 16,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"!\n",
"H\n",
"world\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"# Dictionaries\n",
"my_dict = { 'chr1' : 'gene1', 'chr2' : 'gene3' }\n",
"print(my_dict[ 'chr1' ]) # print gene1 of the dictionary"
],
"metadata": {
"id": "6e6KYBcQ0qa3",
"pycharm": {
"name": "#%%\n"
}
},
"execution_count": 17,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"gene1\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"# Dictionaries2; Find the mistake\n",
"my_dict = { 'chr1' : 'gene1', 'chr2' : 'gene3' }\n",
"print(my_dict[ 'chr1' ]) # print gene1 of the dictionary"
],
"metadata": {
"id": "44dxJxK2bR2n",
"pycharm": {
"name": "#%%\n"
}
},
"execution_count": 18,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"gene1\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"# Dictionaries3\n",
"my_dict = { 'chr1' : ['gene1', 'gene2'], 'chr2' : 'gene3' }\n",
"print(my_dict[ 'chr1' ][ 1 ]) # print gene2 of the dictionary"
],
"metadata": {
"id": "RdIWfnVsbpVF",
"pycharm": {
"name": "#%%\n"
}
},
"execution_count": 19,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"gene2\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"# Booleans\n",
"a = 0\n",
"b = 1\n",
"print(bool( b )) # print True; insert the right variable\n",
"print(bool( a )) # print False; insert the right variable"
],
"metadata": {
"id": "PrmB8FZD0-PQ",
"pycharm": {
"name": "#%%\n"
}
},
"execution_count": 20,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n",
"False\n"
]
}
]
}
]
}
\ No newline at end of file
%% Cell type:markdown id: tags:
# Python course - Exercises Gap text
%% Cell type:markdown id: tags:
Correct the Code
%% Cell type:code id: tags:
```
# What is missing here? Expected output: Hi!
print('Hi!')
```
%% Output
Hi!
%% Cell type:code id: tags:
```
# Here are two mistakes. Can you find them?
# Hi! I am a comment. How are you?
print('Hello world!')
```
%% Output
Hello world!
%% Cell type:code id: tags:
```
# Multi-line comments
"""
I want to be a
mutli line comment.
"""
print('Hello world!')
```
%% Output
Hello world!
%% Cell type:code id: tags:
```
# Expected output: 5
c = 5
print(c)
```
%% Output
5
%% Cell type:code id: tags:
```
# How to print two strings as one. Expected output: Hello world
a = 'Hello '
b = 'world'
print( a + b )
```
%% Output
Hello world
%% Cell type:code id: tags:
```
# Variable types
# Does the error output help you?
a = 'Hello'
b = 0
print( a + str(b) )
```
%% Output
Hello0
%% Cell type:code id: tags:
```
# What is missing?
a = 'Hello'
b = a
if a == b:
print('Same!')
```
%% Output
Same!
%% Cell type:code id: tags:
```
# Print the variable type
# Expected output: a is of type <class 'str'>
a = 'How are you?'
print('a is of type', type(a))
```
%% Output
a is of type <class 'str'>
%% Cell type:code id: tags:
```
# Variable names: What is allowed and what not?
_1th_string = "Hello"
second_string = 'world'
third_string = '!'
FOURTH_STRING = 'How'
FIFTH_STRING = 'are'
_6th_string = 'you?'
print(_1th_string, second_string,
third_string, FOURTH_STRING,
FIFTH_STRING, _6th_string
)
```
%% Output
Hello world ! How are you?
%% Cell type:code id: tags:
```
# convert b into float
a = 2
b = float(a)
print(b)
```
%% Output
2.0
%% Cell type:code id: tags:
```
# How to access Lists?
my_list = ["!", "Hello", 'you', "How", '?', 1, 'are', 2, 3, "world"]
print(my_list)
print(my_list[ 0 ]) # print '!'
print(my_list[ 1 ]) # print 'Hello'
print(my_list[ -1 ]) # print the last element of a list without the real index; here 'world'
### print 'Hello world! How are you?':
print(my_list[ 1 ], my_list[ -1 ] ,my_list[0] ,my_list[ 3 ] ,my_list[ -4 ] ,my_list[ 2 ], my_list[4])
```
%% Output
['!', 'Hello', 'you', 'How', '?', 1, 'are', 2, 3, 'world']
!
Hello
world
Hello world ! How are you ?
%% Cell type:code id: tags:
```
# Indices of Strings
a = 'Hello world!'
print(a[ -1 ]) # only print !
print(a[ 0 ]) # only print H
print(a[ 6:-1 ]) # only print 'world', without '!'
```
%% Output
!
H
world
%% Cell type:code id: tags:
```
# Dictionaries
my_dict = { 'chr1' : 'gene1', 'chr2' : 'gene3' }
print(my_dict[ 'chr1' ]) # print gene1 of the dictionary
```
%% Output
gene1
%% Cell type:code id: tags:
```
# Dictionaries2; Find the mistake
my_dict = { 'chr1' : 'gene1', 'chr2' : 'gene3' }
print(my_dict[ 'chr1' ]) # print gene1 of the dictionary
```
%% Output
gene1
%% Cell type:code id: tags:
```
# Dictionaries3
my_dict = { 'chr1' : ['gene1', 'gene2'], 'chr2' : 'gene3' }
print(my_dict[ 'chr1' ][ 1 ]) # print gene2 of the dictionary
```
%% Output
gene2
%% Cell type:code id: tags:
```
# Booleans
a = 0
b = 1
print(bool( b )) # print True; insert the right variable
print(bool( a )) # print False; insert the right variable
```
%% Output
True
False
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment