Name 3 data types in Python
Nombra 3 tipos de data en Python
what is:
1. Integer (e.g. 4)
2. Float (e.g. 4.0)
3. String (e.g. "hello")
4. Boolean
The OUTPUT of:
cookies = 10
for i in range (5):
cookies -=1
print ('nom nom COOKIE')
print ("I have", cookies+1, "cookies left")
OUTPUT:
nom nom COOKIE
nom nom COOKIE
nom nom COOKIE
nom nom COOKIE
nom nom COOKIE
I have 6 cookies left
"Else If" in python
What is "elif"?
The output of:
phrase = "Is the word here"
print ('word' in phrase)
What is True?
The keyword we need to make a function.
What is "def"?
How do I turn a user input into an integer? Do I have to? What happens if the user inputs a letter?
CODE:
user_input = input("Enter a number: ")
What is:
int(user_input)
Yes, if you want to use math operations.
There will be an error since you can't turn a letter into a number.
The Output of:
dogs = 10
cats = 5
print ("There are %d dogs and %d cats." %(cats,dogs))
what is:
There are 5 dogs and 10 cats.
The difference between:
word = "hello"
for i in range (len(word)):
print(word[i])
for c in word:
print(c)
What is:
One uses indexes to extract character and the other directly works on the element/character
The output of:
number = []
number.append(1)
number.append(3)
number.append ([5,8])
print (number)
number.extend([10,14])
print (number)
What is:
[1,3,[5,8]]
[1,3,[5,8], 10,14]
With a list, append adds whatever is in the parenthesis to the back of the list (the entire list in parenthesis as one element). Extend extracts each element within the list and adds it to the back of the list
The difference between local and global variables.
Local: defined and restricted to the inside of the function
Global: Can be used anywhere in the file. Can be updated/changed anywhere.
The output of:
oranges = 10
apples = 15
print ("I have " + oranges + " oranges and " + apples + " apples.")
The output of:
user_input = input("Enter a number:")
print (user_input * 10)
1. Input: 10
2. Input: a
What is:
1.10101010101010101010
2. aaaaaaaaaa
The output when uinput = "y" and uinput = "N"
CODE:
uinput = input("Do you like the weather? ")
if (uinput == 'y'):
print("I don't")
elif (uinput == 'n'):
print("cool me neither")
else:
print ("what do you mean")
What is:
I don't
What do you mean
word = "banana"
How to print out ALL the indexes where 'n' is
Use a list and a for i loop
What's going to happen?
def hi():
print ("Hey there!")
def hello(word):
return ("Hello " + word)
name = "georgia"
hi()
hello(name)
What is:
Hey there!
The output of:
print (int((float(5.0) + int('2'))) * "hi ")
What is:
hi hi hi hi hi hi hi
fruits = ["apples","peaches", "bananas","oranges"]
How do I print out this list such that the output is:
apples
bananas
Show Solution. But you could use indexing w/ modulo to get and print even indices or splicing.
The output of:
count = 0
while (count < 10):
print ("And I oop-")
count -=1
What is:
Infinity. This will run on forever and forever and forever. And I oop-
Output of:
list = ['b','n','n']
index = 1
for c in range (len(list)):
list.insert(index,'a')
index +=2
print (list)
What is ['b', 'a', 'n', 'a', 'n', 'a']
What is "heya?
def ooga_booga(thing):
return thing[::2]
random_stuff = ['go', 'bananas', 'dab','potato','oop','woah']
heya = ooga_booga(random_stuff)
print (heya)
what is ['go','dab','oop']
thing1 = True
thing2 = False
print (thing1 & (thing2| (thing2 & thing1)| (not thing2)))
Hint: & --> and, | --> or
What is True?
word = "cookie"
How do I get this output? USING A LOOP
Hint: use indexes :)
e
i
k
o
o
c
Show solution
temp = 65
The Output of:
if (temp < 65):
print ("It's cold!")
elif (temp > 65 and temp < 80):
print ("It's alright")
elif (temp >= 80 and temp <= 95):
print ("It's HOT")
else:
print ("It's SCORCHING HOT")
what is:
It's SCORCHING HOT!
The output of:
nums = [1,19,6,10,-4,12,4,18,20,17,-2]
total = 0
for i in range (len(nums)):
if (i % 2 == 0):
total += nums[i]
print (total)
What is 25?
Show code
What is 6?