# [ ] 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[0::-1])
# [ ] 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[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 = "30576"
first_half = int(len(work_tip)/2)
new_work_tip = work_tip[:first_half]
new_work_tip.find("0")
# [ ] print a substring of code_tip set start index = 13 and end index = 25
code_tip = "Make sure to always define your variables"
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("What is your favorite food? ")
for letter in fav_food:
print(letter)
# [ ] 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 letter in work_tip:
if letter == " ":
new_string += "-"
else:
new_string += letter
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"
print(name[1::2])
# [ ] Create Mystery Name
first_name = input("What is your first name? ")
new_name = ""
for letter in first_name[::-1]:
if letter == "e" or letter == "t" or letter == "a":
new_name += "?"
else:
new_name += letter
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"
int(len(topic)/2)
# [ ] print index where first instance of the word "code" starts using .find()
code_tip = "Good code is commented code"
code_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
code_tip.find("code")
code_index = code_tip[13:].find("code")
if code_index == -1:
print("not found")
else:
print("Found at index " + str(code_index))
# [ ] 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"))
index = 0
for letter in code_tip:
if letter == "i":
print("Found an \"i\" at index " + str(index))
index += 1
# [] create words after "G"
# sample quote "Wheresoever you go, go with all your heart" ~ Confucius (551 BC - 479 BC)
quote = input("Quote: ")
word = ""
for letter in quote:
if letter.isalpha():
word += letter
elif word.lower() >= 'h':
print(word.upper())
word = ""
else:
word = ""
if word.lower() >= "h":
print(word.upper())