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
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:-


Related Solutions

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 ?)...
Using Java! Write a program that ask prompt the user to enter a dollar amount as...
Using Java! Write a program that ask prompt the user to enter a dollar amount as double. Then, calculate how many quarters, dimes, nickels and pennies are in the dollar amount. For example: $2.56 = 10 quarters, 1 dime, 1 nickel and 1 cent. Print all of the values. Hint: Use Modulus operator and integer division when necessary.
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...
Write a Python program that will ask the user to input a word, will return the...
Write a Python program that will ask the user to input a word, will return the first letter of the input word, and ask the user to put another word, and so on, in the form of a loop. If the user chooses to stop, he or she should input the integer "0" for the loop to stop.
provide a JavaScript code that finds if the given word by user (prompt) is a Palindrome...
provide a JavaScript code that finds if the given word by user (prompt) is a Palindrome or no.
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...
Java Ask the user to input a letter grade in either upper or lower case. You...
Java Ask the user to input a letter grade in either upper or lower case. You are to output a message depending on the grade. When the input is A or a, output the word "Excellent!" When the input is B or b, output "Very Good" When the input is C or c, output "Satisfactory" For any other input you must output the word "Fail".
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...
using python/IDLE (1) Prompt the user to enter a string of their choosing. Store the text...
using python/IDLE (1) Prompt the user to enter a string of their choosing. Store the text in a string. Output the string. (1 pt) Ex: Enter a sample text: we'll continue our quest in space. there will be more shuttle flights and more shuttle crews and, yes; more volunteers, more civilians, more teachers in space. nothing ends here; our hopes and our journeys continue! You entered: we'll continue our quest in space. there will be more shuttle flights and more...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT