# [ ] access and print the second character from planet_name: "u"
planet_name = "Jupiter"
planet_name = "Jupiter"
print(planet_name[1])
# [ ] access and print the first character from planet_name: "J"
planet_name = "Jupiter"
planet_name = "Jupiter"
print(planet_name[0])
# [ ] access and print the first and last characters from planet_name
planet_name = "Jupiter"
planet_name = "Jupiter"
print(planet_name[0:7:6])
print(planet_name[0]+ planet_name[-1])
# [ ] using a negative index access and print the first character from planet_name: "J"
planet_name = "Jupiter"
planet_name = "Jupiter"
print(planet_name[-7])
# [ ] print planet_name sliced into the first 3 characters and remaining characters
planet_name = "Neptune"
planet_name = "Neptune"
print(planet_name[0:3])
print(planet_name[3:7])
# [ ] print 1st char and then every 3rd char of wise_words
# use string slice with a step
wise_words = 'Play it who opens'
wise_words = "play it who opens"
print(wise_words[0:-1:3])
# [ ] print planet_name in reverse
planet_name = "Neptune"
print(planet_name[-1:-8:-1])
# [ ] find the number of 0's in the first half (slice) of work_tip
work_tip = "1099"
print(work_tip[0:2].count("0"))
# [ ] print a substring of code_tip set start index = 13 and end index = 25
code_tip = "799 is the tip of the code"
print(code_tip[13:26])
# [ ] Get user input for 1 fav_food
# [ ] iterate through letters in fav_food
# - print each letter on a new line
fav_food = input("what is your favorite food?")
for letters in fav_food:
print(letters)
# [ ] iterate work_tip string concatenate each letter to variable: new_string
# [ ] concatenate the letter or a "-" instead of a space " "
# tip: concatenate string example: word = word + "a"
work_tip = "Good code is commented code"
work_tip = "Good code is commented code"
new_string = ""
for letters in work_tip:
if letters == " ":
new_string = new_string + "-"
else:
new_string = new_string + letters
print(new_string)
# [ ] Print the first 4 letters of name on new line
name = "Hiroto"
name = "Hiroto"
for letters in name[0:4]:
print(letters)
# [ ] Print every other letter from 2nd to last letter of name
name = "Hiroto"
name = "Hiroto"
print(name[1:6:2])
# [ ] Create Mystery Name
first_name = input("What is your first name?")
new_name = ""
for letters in first_name[-1:-(len(first_name) + 1):-1]:
if letters == "e" or letters == "t" or letters == "a":
new_name = new_name + "?"
else:
new_name = new_name + letters
print(new_name)
# [ ] find and display the length of the string: topic
topic = ".find() returns the length of a string"
topic = ".find() returns the length of a string"
print(len(topic))
# [ ] use len() to find and display the mid_pt (middle) index (+/- 1) of the string: topic
# note: index values are whole numbers
topic = "len() can take a sequence, like a string, as an argument"
topic = "len() can take a sequence, like a string, as an argument"
print(topic[int(len(topic)/2):len(topic)])
# [ ] print index where first instance of the word "code" starts using .find()
work_tip = "Good code is commented code"
work_tip = "Good code is commented code"
print(work_tip[work_tip.find("code"):len(work_tip)])
# [ ] search for "code" in code_tip using .find()
# [ ] search substring with substring index start= 13,end = last char
# [ ] save result in varible: code_index
# [ ] display index of where "code" is found, or print "not found" if code_index == -1
work_tip = "Good code is commented code"
work_tip = "Good code is commented code"
code_index = ""
code_index = work_tip[13:len(work_tip)].find("code")
if code_index == -1:
print("not found")
else:
print(code_index)
# [ ] find and report (print) number of w's, o's + use of word "code"
work_tip = "Good code is commented code"
work_tip = "Good code is commented code"
print(work_tip.count("w"))
print(work_tip.count("o"))
print(work_tip.count("code"))
# [ ] count times letter "i" appears in code_tip string
# [ ] find and display the index of all the letter i's in code_tip
# Remember: if .find("i") has No Match, -1 is returned
code_tip = "code a conditional decision like you would say it"
print ("code_tip:" , code_tip)
code_tip.find("i", 48)
code_tip = "code a conditional decision like you would say it"
start = 0
while True:
if code_tip.find("i", start) == -1:
break
else:
print(code_tip.find("i", start, -1))
start = code_tip.find("i", start)+1
# [] create words after "G"
# sample quote "Wheresoever you go, go with all your heart" ~ Confucius (551 BC - 479 BC)
quote = input("enter a quote: ")
word = ""
start = 0
for letters in quote:
if letters.isalpha() == False:
if word > "g":
print(word)
word = ""
else:
word = ""
else:
word = word + letters.lower()