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
print("Exercise 1")
print() #For new line
a = input("Three letter word? ") #input from user
print(a) #print that entered string
for i in range(len(a)):
print(a[i]) #print every character in the
string in newline
print() #For new line
output:-
# Exercise 2
print("Exercise 2")
print() #For new
line
a = input("First number? ") #Enter
first number by user
b= input("Second number? ") #Enter
second number by user
inta = int(a)
#convert string into integer by
explicitily
intb = int(b)
#convert string into integer by explicitily
c=inta*intb #multiplication of entered 2 numbers
stra = str(a)
#convert entered string into string
explicitily
strb = str(b)
strproduct = str(c)
sent = "The product of {0} times {1} is {2}"
#Print the sentence in the given format
print(sent.format(stra,strb,strproduct))
print()
output:-
# Exercise 3
print("Exercise 3")
print()
a= input("First name? ") #ask the
user to enter his/her first name
b= input("Last name? ")
#ask the user to enter his/her last name
c= input("Middle initial? ") #ask
the user to enter his/her middle name
sent = "{0} {1}. {2}"
print(sent.format(a,c,b)) #print the
total name in this format
print(a[0])
#print the first letter
print(c[0])
#print the first letter
print(b[0])
#print the first letter
print()
output:-
# Exercise 4
print("Exercise 4")
print()
a = input("six letter cheer? ") #ask the user to enter
6 letter cheer word like booboo, hurray etc
for i in range(len(a)-1):
print(a[i])
#print each character in line by line
print("!")
#Atlast of printing all characters print !
print()
output:-
# Exercise 5
print("Exercise 5")
print()
a = input("birthyear? ") #ask the
user to enter his/her birthyear
inta = int(a)
#convert the entered year into integer by
explicitily
suba = 2019 - inta
#subtract the entered year from 2019
stra = str(a)
#convert the entered year into string by
explicitily
strsuba = str(suba)
sentence = "It has been {0}! years since your birthyear in
{1}!" #print the sentence in this
format
print(sentence.format(strsuba,stra))
print("You were born in the year:",stra)
for i in range(len(a)):
print(a[i])
#print
each character of entered input
print()
output:-
Total output of above program:-