# [ ] access and print the second character from planet_name: "u"
planet_name = "Jupiter"
print(planet_name[1])
# [ ] access and print the first character from planet_name: "J"
planet_name = "Jupiter"
print(planet_name[0])
# [ ] access and print the first and last characters from planet_name
planet_name = "Jupiter"
print(planet_name[0])
print(planet_name[-1])
# [ ] using a negative index access and print the first character from planet_name: "J"
planet_name = "Jupiter"
# [ ] print planet_name sliced into the first 3 characters and remaining characters
planet_name = "Neptune"
print(planet_name[:3])
print(planet_name[3:])
# [ ] print 1st char and then every 3rd char of wise_words
# use string slice with a step
wise_words = 'Play it who opens'
print(wise_words[::3])
# [ ] print planet_name in reverse
print(planet_name[::-1])
# [ ] find the number of 0's in the first half (slice) of work_tip
work_tip = 'save your code'
print(work_tip[:7].count("o"))
# [ ] print a substring of code_tip set start index = 13 and end index = 25
code_tip = "good code has meaningful variable names"
print(code_tip[13:25])
# [ ] Get user input for 1 fav_food
fav_food = input('whats your favorite food? ')
# [ ] iterate through letters in fav_food
# - print each letter on a new line
for pog in fav_food:
print(pog)
# [ ] 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"
new_string = " "
for ltr in work_tip:
if ltr == " ":
ltr = "-"
else:
pass
new_string += ltr
print(new_string)
# [ ] Print the first 4 letters of name on new line
name = "Hiroto"
name = name[:4]
for pog in name:
print(pog)
# [ ] Print every other letter from 2nd to last letter of name
name = "Hiroto"
print(name[1::2])
# [ ] Create Mystery Name
first_name = input('whats your first name? ')
new_name = ""
first_name = first_name[::-1]
for ltr in first_name:
if ltr == "e":
ltr = "?"
elif ltr == "t":
ltr = "?"
elif ltr == "a":
ltr = "?"
else:
pass
new_name += ltr
print(new_name)
# [ ] find and display the length of the string: topic
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"
index = int(len(topic))/2
print(int(index))
print(topic[28])
# [ ] print index where first instance of the word "code" starts using .find()
work_tip = "Good code is commented code"
work_tip.find("code")
# [ ] 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"
code_index = code_tip[13:].find("code")
print('not found:/')
# [ ] find and report (print) number of w's, o's + use of word "code"
work_tip = "Good code is commented code"
work_tip.find("code")
o = work_tip[5:9].count("w")
w = work_tip[5:9].count("o")
int(w)+int(o)
# [ ] 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)
print(code_tip.count("i"))
print(code_tip.find("i"))
print(code_tip[12:].find('i')+12)
print(code_tip[14:].find('i')+14)
print(code_tip[14:].find('i')+16)
print(code_tip[25:].find('i')+25)
print(code_tip[30:].find('i')+30)
# [] create words after "G"
# sample quote "Wheresoever you go, go with all your heart" ~ Confucius (551 BC - 479 BC)
quote = "Wheresoever you go, go with all your heart"
blank = ""
for ltr in quote:
if ltr.isalpha == True:
blank += ltr
elif blank.lower() >= "h":
print(blank)
blank = ""
else:
blank = ""
if blank >= "h":
print(blank)