# [ ] 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[-7])
# [ ] print planet_name sliced into the first 3 characters and remaining characters
planet_name = "Neptune"
print(planet_name[0:])
# [ ] 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[0::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 = "0000000000"
mid_pt = int(len(work_tip)/2)
number = (work_tip[:mid_pt]).count("0")
print(number)
# [ ] print a substring of code_tip set start index = 13 and end index = 25
code_tip = "0000000000011111111111111111111113333333333333"
print(code_tip[13:25])
# [ ] Get user input for 1 fav_food
# [ ] iterate through letters in fav_food
# - print each letter on a new line
fav_food = input("Enter one of your favorite foods: ")
for ltr in fav_food:
print(ltr)
# [ ] 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.isalpha():
new_string += ltr
else:
new_string += "-"
print(new_string)
# [ ] Print the first 4 letters of name on new line
name = "Hiroto"
for letter in name[:4]:
print(letter)
# [ ] Print every other letter from 2nd to last letter of name
name = "Hiroto"
for letter in name[1:-1:2]:
print(letter)
# [ ] Create Mystery Name
first_name = input("Enter your first name: ")
new_name = ""
for letters in first_name[::-1]:
if letters == "e" or letters == "t" or letters == "a":
new_name += "?"
else:
new_name += letters
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"
mid_pt = int(len(topic)/2)
print(mid_pt)
# [ ] print index where first instance of the word "code" starts using .find()
work_tip = "Good code is commented code"
print(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"
search = work_tip.find("code")
code_index = work_tip[13:-1]
if code_index.find("code") == -1:
print("Not found")
else:
print(code_index.find("code"))
# [ ] find and report (print) number of w's, o's + use of word "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)
print(code_tip.count("i"))
for letters in code_tip:
if letters == "i":
print(code_tip.find(letters))
else:
pass
# [] create words after "G"
# sample quote "Wheresoever you go, go with all your heart" ~ Confucius (551 BC - 479 BC)
quote = input("Enter a quote (no punctuation): ")
word = ""
for ltr in quote:
if ltr.isalpha() == True:
word = word + ltr
if (word[0]).lower() > "g":
print(word)
word = ""
else:
word = ""