Chapter one Flashcards
Run python and get it to display hello world
Do it via file as well
cmd
python
print(“Hello, World”)
new file
print(“hello world”)
save as hello.py
click run
start debugging
python
What is the term print known as?
A function
Create a variable called name, ask “what is your name?” and allow it to be input
Next, have the program say hello to you
name = input(“what is your name?” )
Space is intentional at end!
print (“Hello, “ + name”)
What do you call it when text is added to a variable
Like when your name is added to the name variable?
It’s a string
Create two variables and print them
What are the three ways to add spaces to the output so the variables aren’t together?
word1 = “hello “
word2 = “world
print(word1 + word2)
print(word1 + “ “ + word2)
or
space = “ “
print(word1 + space + word2)
Give some examples of slicing
greeting = “Well, hello there!”
hello = [6:11]
print(hello)
or just
print(greeting[6:11])
Via slicing, describe what this means: [6:11]
Everything after 6 up to and including 11
What would these two do in terms of slicing
[:11]
[6:]
[:11] - From the beginning up to and including 11
[6:] - From after 6 to the end of the string
What would these be called in python
3
3.1
3 - interger
3.1 - floating point number / float for short
Create a program that takes the price of coffee that you input and gives you your total for everything
price = input(“What is the price of a cup of coffee? “)
cups = input(“How many cups do you want? “)
total = float(price) * int(cups)
print(“Your total is $” + str(total) + “ for “ + cups + “ cups”)
How do you tell python that you’re creating a float, string, and interger
float(variable)
int(variable)
str(variable)
What do you call it when you change something from a certain type like an interger, float, or string to another type
casting
In the end we are casting the total as a string
Cast numbers from price and cups into another variable
price = input(“Price? “)
cup = input(“Cups? “)
total_price = float(price)
total_cup = int(cup)
How would you create a comment?
#
What is a newline and how do you create one
newline is a break
once you print something to the console it will automatically add one, but if you want to do it manually in the middle of your string, add \n like this:
print(“Hello,\nWorld”)
do two to add two breaks
print(“Hello, World\n\nHello, World”)