Skip to content

Commit 9b8be66

Browse files
committed
style code correctly
Code styled with fenced blocks and syntax highlighting.
1 parent 9526778 commit 9b8be66

File tree

1 file changed

+36
-24
lines changed

1 file changed

+36
-24
lines changed

Day-1/README.md

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,56 +11,66 @@ Open Python IDLE. This opens the output window - we will write our code in a new
1111

1212
In the new window, type this to print something:
1313

14-
print "hello world"
14+
```python
15+
print "hello world"
16+
```
1517

1618
Save the project as a .py extension (you can hit CTRL/CMD + S to save). Hit F5 to run your program.
1719

1820
Create your first variable and print it. In computer language, a variable is what lets the computer remember something. In this case, we want the computer to remember our name.
1921

2022
Below that is a `print` statement that shows you how to print a variable.
2123

22-
print "hello world"
23-
name = "Brian"
24-
print "my name is", name
24+
```python
25+
print "hello world"
26+
name = "Brian"
27+
print "my name is", name
28+
```
2529

2630
The next task is to ask the user for something. That's what `raw_input` does.
2731

2832
We can have the user type in something and store it in a variable.
2933

30-
print "hello world"
31-
name = "Brian"
32-
print "my name is", name
33-
34-
your_name = raw_input("What is your name?")
34+
```python
35+
print "hello world"
36+
name = "Brian"
37+
print "my name is", name
3538

39+
your_name = raw_input("What is your name?")
40+
```
41+
3642
If you run this, you'll see that there's no space between the `?` and the user's input. We can fix this by adding a space in.
3743

3844
When you use `raw_input`, it stores what the user typed in in a variable. We can print the info the user typed in:
3945

40-
print "hello world"
41-
name = "Brian"
42-
print "my name is", name
43-
44-
your_name = raw_input("What is your name? ")
45-
print "your name is", your_name
46+
```python
47+
print "hello world"
48+
name = "Brian"
49+
print "my name is", name
4650

51+
your_name = raw_input("What is your name? ")
52+
print "your name is", your_name
53+
```
54+
4755
You can use `raw_input` to ask the user for strings - things like names and sentences.
4856
If you use `input`, Python will try to change what the user typed into a number.
4957

50-
print "hello world"
51-
name = "Brian"
52-
print "my name is", name
58+
```python
59+
print "hello world"
60+
name = "Brian"
61+
print "my name is", name
5362

54-
your_name = raw_input("What is your name? ")
55-
print "your name is", your_name
56-
your_age = input("How old are you? ")
57-
print "in a year you will be", your_age+1, "years old"
63+
your_name = raw_input("What is your name? ")
64+
print "your name is", your_name
65+
your_age = input("How old are you? ")
66+
print "in a year you will be", your_age+1, "years old"
67+
```
5868

5969
If you try to type "nine" when it asks for the age, it won't work. Python doesn't know what "nine" is, it only know the digit "9".
6070

6171
There are two types of variables we'll be using today: strings (things like words, sentences), and integers (whole numbers). Python thinks "nine" is a string, and can't change it to a number.
6272

63-
**Bonus challenge: In the example above, we added 1 to your age and told you how old you will be in a year. Can you set a new variable years_to_100 that will calculate how many years until you turn 100? Then print out the variable with a message.
73+
**Bonus challenge**: In the example above, we added 1 to your age and told you how old you will be in a year. Can you set a new variable years_to_100 that will calculate how many years until you turn 100? Then print out the variable with a message.
6474

6575
##Reading and Altering Code - Number Guess Game
6676

@@ -112,7 +122,9 @@ We'll be making a lot more changes to this program to get it to do what we want.
112122

113123
You could use a for loop that repeats code a specific number of times. This line will repeat the indented code 10 times:
114124

115-
for num in range(0,10):
125+
```python
126+
for num in range(0,10):
127+
```
116128

117129
You could also use a while loop and count yourself. See how the number guess game counted the number of tries.
118130

0 commit comments

Comments
 (0)