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.
Flowchart + Python. Ask the user for a value. Then, ask the user for the number...
Flowchart + Python. Ask the user for a value. Then, ask the user for the number of expressions of that value. Use While Loops to make a program. So then, it should be so that 5 expressions for the value 9 would be: 9 * 1 = 9 9 * 2 = 18 9 * 3 = 27 9 * 4 = 36 9 * 5 = 45 Flowcharts and Python Code. Not just Python code. I cannot read handwriting....
Using Python write a program that does the following in order: 1. Ask user to enter...
Using Python write a program that does the following in order: 1. Ask user to enter a name 2. Ask the user to enter five numbers “amount1”, “amount2”, “amount3”, “amount4”, “amount5” 3. Calculate the sum of the numbers “amount1”, “amount2”, “amount3”, “amount4”, “amount5” 4. If the sum is greater than 0, print out the sum 5. If the sum is equal to zero, print out “Your account balance is zero” 6. If the sum is less than 0, print out...
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.
Using map - java - eclipse Prompt the user for the skillset to add. A skillset...
Using map - java - eclipse Prompt the user for the skillset to add. A skillset can be any String. Examples of skillsets are: “java” “software design”, “databases”, etc. Add the skillset to the logged in user’s skillsets and then provide a response to the logged in user indicating that their skillset has been added (e.g. “Java has been added to your skillsets.”). You don’t have to display any additional messages if the user added a duplicate skillset. In this...
C++ while loop Exercise Write a program that continues to ask the user to enter any...
C++ while loop Exercise Write a program that continues to ask the user to enter any set of numbers, until the user enters the number -1. Then display the total sum of numbers entered and their average. (note that you need to define a counter that counts how many numbers so the average = (sum/n) where n is your counter total. #include <iostream> using namespace std; int main() { int number, n=0, sum=0; cout << "Enter a number to start...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT