In: Computer Science
Pythpn
#Exercise 1
#Ask the user for a three letter word using the prompt: three
letter word? (include a space after the ?)
#Display the entire word
#Display the word vertically, one letter at a time using print
statements and the string index
#For example, if the user enters baa, the output should be (ignore
# signs):
#baa
#b
#a
#a
#Exercise 2
#Ask the user for a number using the prompt: first number? (include
a space after the ?)
#Ask the user for a number using the prompt: second number?
(include a space after the ?)
#Convert both numbers to integers
#Calculate the product of the two numbers
#Convert the two numbers and the product to strings using the str()
function
#Display the following on screen using a print statement and the +
concatenator.(note the spacing esp no space before the .)
#The product of [first number] times [second number] is
[product].
#For example, if the user entered 2 and 3, the final output should
be:
#The product of 2 times 3 is 6.
#Exercise 3
#Ask the user for a first name using the prompt: first name?
(include a space after the ?)
#Ask the user for a last name using the prompt: last name? (include
a space after the ?)
#Ask the user for a middle inital using the prompt: middle initial?
(include a space after the ?)
#Display the user entered full name in the following format [first
name] {middle inital]. [last nmae] (note the .)
#For example, if the user entered Malu Roldan H in response to the
input statements, the output should be:
#Malu H. Roldan
#Next, display the user's initials one letter at a time vertically.
For example, for Malu H. Roldan,
#the output should be (ignore # signs):
#M
#H
#R
#Exercise 4
#Ask the user for a six letter cheer using the prompt: six letter
cheer? (include a space after the ?)
#Display the entire cheer with an exclamation point after it (e.g.
if user enters boohoo, display boohoo!)
#Display the cheer vertically, one letter at a time ending with an
exclamation point in the last line
#For example, for user entry boohoo, display (ignore #
signs):
#b
#o
#o
#h
#o
#o
#!
#Exercise 5
#a Ask the user for a birth year using the prompt: birthyear?
(include a space after the ?)
#b Convert the user input to an integer
#c Subtract the user entered birthyear from 2019
#d Convert the result of the previous line and the user entry to
strings using the str() function
#e Display the following using the + concatenator in a print
statement (note the punctuation and spacing):
#f It has been [converted result of line 5c]! years since your
birthyear in [converted user entry]!
#g Hence, if user entered 2010, display:
#h It has been 9! years since your birthyear in 2010
#i Next, display the words: You were born in the year:
#j Display the converted user entered birthyear vertically, one
digit at a time.
#k For example, for 2010 display (ignore the # signs):
#2
#0
#1
#0
Exercise 1
word=input('three letter Word: ') # read input string with space
for char in word: # create for loop until word
print(char) # display character by character of word
##OUTPUT
#three letter Word: baa
#b
#a
#a
Exercise 2
first=input("First Number? ") # read first number in string
format
second=input("Second Number? ") # read second number in string
format
a=int(first) # convert first number into integer
b=int(second) # conver second number into integer
print('The product of',str(a),'times',str(b),'is',a*b) # display output result in product value
##OUTPUT
##
##First Number? 2
##Second Number? 3
##The product of 2 times 3 is 6
Exercise 3
first=input('First Name? ') # Read first name
last=input('Last Name? ') # Read last name
mid=input('Middle Initial? ') # Read middle name
final=first+" "+mid+" "+last # concatnate first,mid,last name
into final
print(final) #display full name
print(final[0]) #display first character from final string
for val in range(len(final)): # create for loop until lenth of
final string
if final[val]==" ": # check the string = '' then,
print(final[val+1]) # display first character of the each word in
vertically
##OUTPUT
##
##First Name? Malu
##Last Name? Roldan
##Middle Initial? H.
##Malu H. Roldan
##M
##H
##R
Exercise 4
cheer=input('six letter cheer? ') # input six letter string
for letter in range(len(cheer)): # create for loop until length
of cheer string
print(cheer[letter]) # print letter by letter in vertically
print("!") # and display final character is '!'
##OUTPUT
##
##six letter cheer? boohoo
##b
##o
##o
##h
##o
##o
##!
Exercise 5
year=input('birth year?') # Read birth year in string format
y=int(year) # convert birth year into integer and store in y
variable
sub_year=2019-y # subtract 2019-birthyear and store result
sub_year
# display following format with subtracted value
# USING FORMAT function
# {0} represent first value
# {1} represent second value
print('It has been {0}! years since your birth year in
{1}'.format(sub_year,year))
print('\n'.join(map(str,year))) # finally display the given year in vertical format
##OUTPUT
##
##birth year?2010
##It has been 9! years since your birth year in 2010
##2
##0
##1
##0
SCREENSHOTS
Exercise-1
Exercise-2
Exercise-3
Exercise-4
Exercise-5