You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Day-1/README.md
+36-24Lines changed: 36 additions & 24 deletions
Original file line number
Diff line number
Diff line change
@@ -11,56 +11,66 @@ Open Python IDLE. This opens the output window - we will write our code in a new
11
11
12
12
In the new window, type this to print something:
13
13
14
-
print "hello world"
14
+
```python
15
+
print"hello world"
16
+
```
15
17
16
18
Save the project as a .py extension (you can hit CTRL/CMD + S to save). Hit F5 to run your program.
17
19
18
20
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.
19
21
20
22
Below that is a `print` statement that shows you how to print a variable.
21
23
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
+
```
25
29
26
30
The next task is to ask the user for something. That's what `raw_input` does.
27
31
28
32
We can have the user type in something and store it in a variable.
29
33
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
35
38
39
+
your_name =raw_input("What is your name?")
40
+
```
41
+
36
42
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.
37
43
38
44
When you use `raw_input`, it stores what the user typed in in a variable. We can print the info the user typed in:
39
45
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
46
50
51
+
your_name =raw_input("What is your name? ")
52
+
print"your name is", your_name
53
+
```
54
+
47
55
You can use `raw_input` to ask the user for strings - things like names and sentences.
48
56
If you use `input`, Python will try to change what the user typed into a number.
49
57
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
53
62
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
+
```
58
68
59
69
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".
60
70
61
71
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.
62
72
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.
64
74
65
75
##Reading and Altering Code - Number Guess Game
66
76
@@ -112,7 +122,9 @@ We'll be making a lot more changes to this program to get it to do what we want.
112
122
113
123
You could use a for loop that repeats code a specific number of times. This line will repeat the indented code 10 times:
114
124
115
-
for num in range(0,10):
125
+
```python
126
+
for num inrange(0,10):
127
+
```
116
128
117
129
You could also use a while loop and count yourself. See how the number guess game counted the number of tries.
0 commit comments