8000 Make a better exercises workflow and update best_practices. · fdani1/intro-to-python@2077d35 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2077d35

Browse files
committed
Make a better exercises workflow and update best_practices.
1 parent 7e20b18 commit 2077d35

File tree

20 files changed

+572
-219
lines changed

20 files changed

+572
-219
lines changed

best_practices.md

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
# Best practices for when you are working on exercises
22

3+
### Commenting out shortcut
4+
- Select the lines you want to comment and press:
5+
- Windows: ```Ctrl + / ```
6+
- Mac: ```Command + /```
37

4-
Navigate the folders using the command-line and create your <homework_sessionNumber.py> (ex: homework_2.py) file:
8+
---
9+
10+
## When you start:
11+
12+
First, make sure you are using the shell (not the console).
13+
14+
Using the bash shell, navigate the folders using the command-line and make sure you are in the same folder as the files you want to access. Ex: In order to access `exercises_1.py`, you have to be in `intro-to-python/session_01`.
15+
16+
Here are some CLI commands to help you out:
517

618
```bash
719
pwd # Prints to the console the path of your current working directory
@@ -13,25 +25,19 @@ cd <directory_name> # Gets in a given directory
1325

1426
cd .. # Gets out of the directory you are in
1527

28+
```
1629

30+
---
1731

18-
mkdir <directory_name> # Creates new directory
19-
20-
rmdir my_folder # Deletes an empty Directory (Folder)
21-
22-
rm -r <directory_name> # Deletes the directory and its contents recursively
23-
24-
25-
touch <file_name.txt/file_name.py> # Creates new file
26-
27-
rm <file_name.txt/file_name.py> # Deletes file
28-
29-
30-
31-
```
32+
## How do you run a python file?
33+
1. Make sure that you are using the shell.
34+
1. Verify that you are in the folder containing the file you want to run. You can use `pwd` to check the current folder and `ls` to see the files in the current folder.
35+
2. Run `python <file_name.py>` (ex: `python session_1.py`).
3236

3337
---
3438

39+
## Before you go:
40+
3541
When you are done for the day, don't forget to commit and push your work using the git commands:
3642

3743
```shell

session_00/exercises_0.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
```bash
2+
pwd # Prints to the console the path of your current working directory
3+
4+
ls # Lists the files in the directory you are in
5+
6+
7+
cd <directory_name> # Gets in a given directory
8+
9+
cd .. # Gets out of the directory you are in
10+
11+
12+
13+
mkdir <directory_name> # Creates new directory
14+
15+
rmdir my_folder # Deletes an empty Directory (Folder)
16+
17+
rm -r <directory_name> # Deletes the directory and its contents recursively
18+
19+
20+
touch <file_name.txt/file_name.py> # Creates new file
21+
22+
rm <file_name.txt/file_name.py> # Deletes file
23+
24+
25+
26+
```
27+
28+
29+
When you are done for the day, don't forget to commit and push your work using the git commands:
30+
31+
```shell
32+
33+
git add . # Adds ALL changes to the staging area in preparation for committing them to the repository.​
34+
35+
git commit -m "<Short description of what you have worked on.>" # Saves changes to the local repository, along with your commit message, usually describing the changes.
36+
37+
git push origin main # Uploads local changes to your remote repository, on the main branch.
38+
```
39+

session_01/exercises_1.md

Lines changed: 0 additions & 19 deletions
This file was deleted.

session_01/exercises_1.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Session 1 Exercises
2+
3+
# Please have a look at the best_practices.md file beforehand.
4+
5+
6+
## Section A
7+
# 1. Write code that prints ‘Hello world’.
8+
9+
10+
# 2. Print the numbers 1 to 5 on a single line.
11+
12+
13+
14+
# 3. Write a script where ‘Hello’ and ‘World’ are printed on two separate lines.
15+
16+
17+
18+
# 4. Write a script that prints a list of names, tabbed on separate lines, e.g.
19+
# ```My List of Names:
20+
# Alice
21+
# Bob
22+
# Charlie
23+
# ```
24+
25+
26+
27+
28+
# <---------------------------------------------------------------------------------------------->
29+
30+
## Section B
31+
# 1. Write code that prints the value of 2 + 2.
32+
33+
34+
35+
# 2. Write code that prints the value of 5.7 subtracted from 3.4.
36+
37+
38+
39+
# 3. Write code that prints the value of 8 multiplied by 7.
40+
41+
42+
43+
# 4. Write code that prints the value of 144 divided by 12.
44+
45+
46+
47+
# 5. Write code that prints the value of the remainder of 67 divided by 12.
48+
49+
50+
51+
# 6. Write code that finds the value of 20 from `4 - 2 * 6 / 3 * 5`. Hint: you might need brackets.

session_02/exercises_2.md

Lines changed: 0 additions & 17 deletions
This file was deleted.

session_02/exercises_2.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Session 2 Exercises
2+
3+
## Section A
4+
# 1. Create two variables that hold the width and height of a rectangle, work out and store the area in a third variable.
5+
# Print out the string: `Rectangle of width <x> and height <y> has an area of <area>`.
6+
7+
8+
9+
# 2. Write code that prints the length of the string, 'python'.
10+
11+
12+
13+
# 3. Print out the first and third letter of the word 'python'.
14+
15+
16+
17+
# 4. Ask the user to enter their name, and print out `Hello, <name>`.
18+
19+
20+
21+
# 5. Ask the user to enter their age, tell them how old they will be in 15 years time.
22+
23+
24+
25+
# 6. Combine the two input statements above and print out the message `Hello, <name>, you are currently <age> years old.
26+
# In 15 years time you will be <age_in_15_years_time>`.
27+
28+
29+
30+
# 7. Ask the user to enter their hometown, print it out in uppercase letters.
31+
32+
33+
34+
# 8. Ask the user to enter their favourite colour and find out the length of the colour they input.
35+
36+
37+
38+
# 9. Ask the user to enter the weather and the month. Print out the string, `It is <month> and it is <weather> today`.
39+
40+
41+
42+
# 10. Ask the user to enter 5 different temperatures and the month. Work out the average temperature and print out the string:
43+
# `It is <month> and the average temperature is <average_temperature> degrees celsius`.
44+
45+
46+
47+
# 11. Print out the above sentence but make the month upper case.
48+
49+
50+
51+
# 12. Create a variable that holds your favourite animals and print it out.
52+
# Make sure the animals are all on different lines and tabbed.
53+
54+
55+
56+
# 13. Ask the user to enter their name as well as a number.
57+
# Print out the uppercase character at that position in the string.
58+
59+
60+
61+
# 14. Slice the string with steps of 2, excluding the first and last characters of the string "WelcometoPython".

session_03/exercises_3.md

Lines changed: 0 additions & 33 deletions
This file was deleted.

session_03/exercises_3.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Session 3 Exercises
2+
3+
## Section A
4+
# 1. Ask for the user's name, if they are called "Bob", print "Welcome Bob!".
5+
6+
7+
8+
# 2. Ask for the user's name, if they are not called "Alice", print "You're not Alice!".
9+
10+
11+
12+
# 3. Ask the user for a password, if they enter the password "qwerty123", print "You have successfully logged in".
13+
# If they get it wrong, print "Password failure".
14+
15+
16+
17+
# 4. Ask the user to enter a number, if the number is even, print "Even", otherwise print "Odd".
18+
19+
20+
21+
# 5. Ask the user for 2 different numbers, if the total of the two numbers is over 21, print "Bust" otherwise print "Safe"
22+
23+
24+
25+
# 6. Ask the user to enter the length and width of a shape and check if it is a square or not.
26+
27+
28+
29+
# 7. You have had a great year and are going to offer a bonus of 10% to any employee who has a service of over 3 years.
30+
# Ask the user to input their current salary and years of service and print out their salary and their bonus or "No bonus" if they are not receiving one.
31+
32+
33+
34+
# 8. Take a whole number input, if it's positive, print out the number cubed, if it is a negative, print out half its value.
35+
36+
37+
38+
39+
# <---------------------------------------------------------------------------------------------->
40+
41+
## Section B
42+
# 1. Ask for the user's name, if they are called "Alice" print "Hello, Alice", if they are called "Bob",
43+
# print "You're not Bob! I'm Bob", else print "You must be Charlie".
44+
45+
46+
47+
# 2. Ask the user to enter their age:
48+
# 1. If they are younger than 11, print "You're too young to go to this school"
49+
# 2. If they are between 11 and 16, print "You can can come to this school"
50+
# 3. If they are over 16, print 'You're too old for school"
51+
# 4. If they are 0, print "You're not born yet!"
52+
53+
54+
55+
# 3. Ask the user to enter the name of a month. If the user enters March/April/May: print "<month> is in Spring", otherwise print "I don't know".
56+
# 1. Expand for the rest of the year, given that summer is June/July/August. Autumn is September/October/November. Winter is December/January/February.
57+
# 2. Ensure that when an unknown month is given it prints "I don't know".
58+
59+
60+
61+
# 4. Ask the user for two different numbers, if both numbers are even, print "Even", if both numbers are odd, print "Odd", else print the product of the two numbers.
62+
63+
64+
65+
# 5. Ask the user to input two numbers. Decide which is the number of highest value and print this out.
66+
67+
68+
69+
# 6. You have had a fantastic year and are now going to offer a bonus of 20% to any employee who has a service of over 7 years,
70+
# a bonus of 15% to any employee who has a service of over 5 years and a bonus of 10% to any employee who has a service of 3 - 5 years.
71+
# Ask the user to input their current salary and years of service and print out their salary and their bonus or "No bonus" if they are not receiving one.
72+
73+
74+
75+
# 7. Take the age and name of three people and determine who is the oldest and youngest and print out the name and age of the oldest and youngest.
76+
# If all three ages are the same, print that.
77+
78+
79+
80+
# 8. A school has following rules for their grading system:
81+
# a. Above 80 – A
82+
# b. 60 to 80 – B
83+
# c. 50 to 60 – C
84+
# d. 45 to 50 – D
85+
# e. 25 to 45 – E
86+
# f. Below 25 - F
87+
# Ask user to enter the lesson and the marks for three lessons and print out the corresponding grades for the lesson.

0 commit comments

Comments
 (0)
0