Question

In: Computer Science

Pythpn #Exercise 1 #Ask the user for a three letter word using the prompt: three letter...

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

Solutions

Expert Solution

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


Related Solutions

Create in C++ Prompt the user to enter a 3-letter abbreviation or a day of the...
Create in C++ Prompt the user to enter a 3-letter abbreviation or a day of the week and display the full name of the day of the week. Use an enumerated data type to solve this problem. Enumerate the days of the week in a data type. Start with Monday and end with Friday. Set all of the characters of the user input to lower case. Set an enumerated value based on the user input. Create a function that displays...
Prompt the user for their name, get and store the user input. Prompt the user for...
Prompt the user for their name, get and store the user input. Prompt the user for their age, get and store the user input. We will assume that the user will enter a positive integer and will do no error checking for valid input. Determine and store a movie ticket price based on the user's age. If their age is 12 or under, the ticket price is $5. If their age is between 13 and 64, inclusive, the ticket price...
Python #Use an input statement to ask the user for his/her age (no prompt) and assign...
Python #Use an input statement to ask the user for his/her age (no prompt) and assign the user entry to a variable #Convert the user input to an integer and assign to a variable #Write if-elif-else statements with the following conditions and actions #Important: For each Action below, use the same variable name for the rating in all the if, elif, and else statements #Condition: user input less than or equal to 9 Action: assign the letter G as a...
Prompt the user to enter an integer Then, prompt the user to enter a positive integer...
Prompt the user to enter an integer Then, prompt the user to enter a positive integer n2. Print out all the numbers that are entered after the last occurrence of n1 and whether each one is even or odd If n1 does not occur or there are no values after the last occurrence of n1, print out the message as indicated in the sample runs below. Sample: Enter n1: -2 Enter n2: 7 Enter 7 values: -2 3 3 -2...
Ask the user for a filename, then ask the user for a line of text. Write...
Ask the user for a filename, then ask the user for a line of text. Write the line of text the filename specified by the user. The filename may be absolute or relative to the project directory.
Using Java, write a program named MyAngles that will prompt the user for the measure of...
Using Java, write a program named MyAngles that will prompt the user for the measure of the three sides of a triangle and then reports the measurement of each interior angle of the triangle and the area of the triangle.
: Find the inverse of the three matrices listed below. The code should prompt the user...
: Find the inverse of the three matrices listed below. The code should prompt the user to input the size of the matrix and to put the value of each element in the matrix. The output should contain the solution to the inverse from using a function created by you, and the solution found using the NumPy package. I1 = [ 1 2 3 4]−1 I2 = [ 1 2 3 4 5 6 7 2 9 ] −1 I3...
Write a program that ask the user for three integers. Use two functions to determine the...
Write a program that ask the user for three integers. Use two functions to determine the largest and smallest number of the three. One function will determine the largest number, and the other function will determine the smallest number. (6 points) In c++ using functions.
Write a program using C language that -ask the user to enter their name or any...
Write a program using C language that -ask the user to enter their name or any other string (must be able to handle multiple word strings) - capture the epoch time in seconds and the corresponding nanoseconds - ask the user to type in again what they entered previously - capture the epoch time in seconds and the corresponding nanoseconds -perform the appropriate mathematical calculations to see how long it took in seconds and nanoseconds (should show to 9 decimal...
Using C++ Write a program to ask user to enter a password and validity the password....
Using C++ Write a program to ask user to enter a password and validity the password. The password should be 8 – 20 characters long (8 is included and 20 is included), it should contain at least one uppercase letter and one lower case letter. The password should contain at least one digit, and at least one symbol other than alphabets or numbers. Most importantly, the password may not contain any white space. Functions: You will need at least the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT