variables and data types 005

Go into your folder in PyCharm that you made in the previous post. Delete everything from last time. Type in this in your editor 

print("there was once a girl named Jane,");
print("she was 27 years old");
print("she liked to be 27 years old and likes her name, Jane");

If you run this, it will write a little story, but if you want to change the name or age, you would have to change it in two spots. You can change the name from one spot and the same with age using variables. There are two steps to make the variable we need: 1 put the name you want for the variable on the top, mine will be character_name, and character_age. 2 put a = sign next to it then place quotation marks, and inside of them type the name of the character_name but do the same for character_age except for the quotation marks. Then change your code to this:

print("there was once a girl named " + character_name + ", " );
print("she was " + character_age + " years old");
print("she liked to be " + character_age + " years old and likes her name " + character_name);

Now you have worked with some variables, let me tell you what. The character_name is a string that is just an understandable line of text. character_age is only numbers like this 123, and amounts can go into decimals like 16.946583 so, this can go to any number. Then there's one more that I did not include in this post yet but is called a boolean, which can hold a true/false value. You might not use booleans very often in the world, but they are super important in code. In the next post, we will talk more about strings.

No comments:

Post a Comment

numbers in depth 006