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
Gerald W. Höfner
Python programming
Commits
61378c05
Commit
61378c05
authored
8 months ago
by
Bianca Laker
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
c39cfe55
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Excercises/gap_exercise1_basics.ipynb
+275
-0
275 additions, 0 deletions
Excercises/gap_exercise1_basics.ipynb
with
275 additions
and
0 deletions
Excercises/gap_exercise1_basics.ipynb
0 → 100644
+
275
−
0
View file @
61378c05
{
"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"
}
},
{
"cell_type": "markdown",
"source": [
"Correct the Code"
],
"metadata": {
"id": "uW9SoYEyrlRL"
}
},
{
"cell_type": "code",
"source": [
"# What is missing here? Expected output: Hi!\n",
" ('Hi!')"
],
"metadata": {
"id": "Qflb9AWfrykh"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# Here are two mistakes. Can you find them?\n",
" Hi! I am a comment. How are you?\n",
"\n",
" print('Hello world!')"
],
"metadata": {
"id": "eemU0jTksxu5"
},
"execution_count": null,
"outputs": []
},
{
"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"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# Expected output: 5\n",
"c = 5 \n",
"print( )"
],
"metadata": {
"id": "Vexbuvx1u1NS"
},
"execution_count": null,
"outputs": []
},
{
"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"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# Variable types\n",
"# Does the error output help you?\n",
"a = 'Hello'\n",
"b = 0 \n",
"print( a + b )"
],
"metadata": {
"id": "6QiU3l2_xFnP"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# What is missing?\n",
"a = 'Hello'\n",
"b = a\n",
"\n",
"if a == b:\n",
"print('Same!')"
],
"metadata": {
"id": "_YtGF9xqzFoR"
},
"execution_count": null,
"outputs": []
},
{
"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', (a))"
],
"metadata": {
"id": "wH0ifA4czyDV"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# Variable names: What is allowed and what not?\n",
"_1th_string = \"Hello\"\n",
"second_string = 'world'\n",
"3rd_string = '!'\n",
"FOURTH_STRING = 'How'\n",
"FIFTH STRING = 'are'\n",
"_6th-string = 'you?'\n",
"\n",
"print(_1th_string, second_string, \n",
" 3rd_string, FOURTH_STRING,\n",
" FIFTH STRING, _6th-string\n",
" )"
],
"metadata": {
"id": "Spcu5lGc0Uv9"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# convert b into float\n",
"a = 2\n",
"b = (a)\n",
"print(b)"
],
"metadata": {
"id": "_TcdURMh2yJZ"
},
"execution_count": null,
"outputs": []
},
{
"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[ ]) # print '!'\n",
"print(my_list[ ]) # print 'Hello'\n",
"print(my_list[ ]) # print the last element of a list without the real index; here 'world'\n",
"### print 'Hello world! How are you?':\n",
"print(my_list[ ], my_list[ ] ,my_list[0] ,my_list[ ] ,my_list[ ] ,my_list[ ], my_list[4])"
],
"metadata": {
"id": "5VripGXYxBf8"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# Indices of Strings\n",
"a = 'Hello world!'\n",
"print(a[ ]) # only print !\n",
"print(a[ ]) # only print H\n",
"print(a[ ]) # only print 'world', without '!'"
],
"metadata": {
"id": "V3VJP2gg1HLT"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# Dictionaries\n",
"my_dict = { 'chr1' : 'gene1', 'chr2' : 'gene3' }\n",
"print(my_dict[ ]) # print gene1 of the dictionary"
],
"metadata": {
"id": "6e6KYBcQ0qa3"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# Dictionaries2; Find the mistake\n",
"my_dict = { 'chr1' : 'gene1', 'chr1' : 'gene3' }\n",
"print(my_dict[ ]) # print gene1 of the dictionary"
],
"metadata": {
"id": "44dxJxK2bR2n"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# Dictionaries3\n",
"my_dict = { 'chr1' : ['gene1', 'gene2'], 'chr2' : 'gene3' }\n",
"print(my_dict[ ][ ]) # print gene2 of the dictionary"
],
"metadata": {
"id": "RdIWfnVsbpVF"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# Booleans\n",
"a = 0\n",
"b = 1\n",
"print(bool( )) # print True; insert the right variable\n",
"print(bool( )) # print False; insert the right variable"
],
"metadata": {
"id": "PrmB8FZD0-PQ"
},
"execution_count": null,
"outputs": []
}
]
}
%% 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!
('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!')
```
%% Cell type:code id: tags:
```
# Multi-line comments
I want to be a
mutli line comment.
"""
print('Hello world!')
```
%% Cell type:code id: tags:
```
# Expected output: 5
c = 5
print( )
```
%% Cell type:code id: tags:
```
# How to print two strings as one. Expected output: Hello world
a = 'Hello'
b = 'world'
print( a b )
```
%% Cell type:code id: tags:
```
# Variable types
# Does the error output help you?
a = 'Hello'
b = 0
print( a + b )
```
%% Cell type:code id: tags:
```
# What is missing?
a = 'Hello'
b = a
if a == b:
print('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', (a))
```
%% Cell type:code id: tags:
```
# Variable names: What is allowed and what not?
_1th_string = "Hello"
second_string = 'world'
3rd_string = '!'
FOURTH_STRING = 'How'
FIFTH STRING = 'are'
_6th-string = 'you?'
print(_1th_string, second_string,
3rd_string, FOURTH_STRING,
FIFTH STRING, _6th-string
)
```
%% Cell type:code id: tags:
```
# convert b into float
a = 2
b = (a)
print(b)
```
%% 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[ ]) # print '!'
print(my_list[ ]) # print 'Hello'
print(my_list[ ]) # print the last element of a list without the real index; here 'world'
### print 'Hello world! How are you?':
print(my_list[ ], my_list[ ] ,my_list[0] ,my_list[ ] ,my_list[ ] ,my_list[ ], my_list[4])
```
%% Cell type:code id: tags:
```
# Indices of Strings
a = 'Hello world!'
print(a[ ]) # only print !
print(a[ ]) # only print H
print(a[ ]) # only print 'world', without '!'
```
%% Cell type:code id: tags:
```
# Dictionaries
my_dict = { 'chr1' : 'gene1', 'chr2' : 'gene3' }
print(my_dict[ ]) # print gene1 of the dictionary
```
%% Cell type:code id: tags:
```
# Dictionaries2; Find the mistake
my_dict = { 'chr1' : 'gene1', 'chr1' : 'gene3' }
print(my_dict[ ]) # print gene1 of the dictionary
```
%% Cell type:code id: tags:
```
# Dictionaries3
my_dict = { 'chr1' : ['gene1', 'gene2'], 'chr2' : 'gene3' }
print(my_dict[ ][ ]) # print gene2 of the dictionary
```
%% Cell type:code id: tags:
```
# Booleans
a = 0
b = 1
print(bool( )) # print True; insert the right variable
print(bool( )) # print False; insert the right variable
```
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