Question

How do i write code that prints Goodbye if 1 is stored in home, prints Farewell...

How do i write code that prints Goodbye if 1 is stored in home, prints Farewell if 2 is stored in home, and prints So Long! if anything else is stored in home?
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: You did not mention any language. I have provided the code in python. If you require in any other language do let me know via comments. Thanks

Code:

#function to print the output as given

def printOutput(home):

    if home == 1:

        print("Goodbye ")

    elif home == 2:

        print("Farewell")

    else:

        print("So Long!")

#main driver program

printOutput(1)

printOutput(2)

printOutput(5)

Output:

Add a comment
Know the answer?
Add Answer to:
How do i write code that prints Goodbye if 1 is stored in home, prints Farewell...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write an if-else statement that prints "Goodbye" if userString is "Quit", else prints "Hello". End with...

    Write an if-else statement that prints "Goodbye" if userString is "Quit", else prints "Hello". End with newline. IN C

  • I want to write a code in phyton that prints only letters from input but skips...

    I want to write a code in phyton that prints only letters from input but skips two and prints one. I want my program to do this; input = 2ab4c#fd56gjl output = afj So it should completely ignore any character other than letters and print the letters by skipping 2. (Should i use for loop? My classes just beyan so i am guessing the answer code should be a primitive code.)

  • How to write a bash shell script that prints a hollow box after user enters number...

    How to write a bash shell script that prints a hollow box after user enters number of lines, ie "bash hbox 4" , prints: **** *   * *   * **** My code doesnt work. i need it to take in the argument from the command line: ./hbox 4 "*" echo "Enter number of rows" read sz clear for (( x = 1; x <= $sz; x++ )); do     for (( y = 1; y <= $sz; y++ )); do...

  • How do I write a JavaScript program that prints a welcome message in a large blue...

    How do I write a JavaScript program that prints a welcome message in a large blue font?

  • Please write the complete code in C. Write a C function that prints the minimum spanning...

    Please write the complete code in C. Write a C function that prints the minimum spanning tree of a graph. At the end, print the weight of the spanning tree. A suggested report format is shown in the following example. Source Vertex To Vertex Weight A B 2 A C 4 B D 3 D E 1 Total weight of spanning tree: 10 Your main program will read a graph from DataIn file to an adjacency table before calling the...

  • Write a C program as follows: Single source code file Uses an infinite loop Requests the...

    Write a C program as follows: Single source code file Uses an infinite loop Requests the user to press a key Uses a nested switch statement Either prints the key pressed, or terminates using the break statement and prints Goodbye! if the user presses either the e or E key Please include lots of comments please, this is how I learn how to code. I need LOTS of comments!

  • # 3. PUT IN PYTHON CODE # Write a program that prints a count of how...

    # 3. PUT IN PYTHON CODE # Write a program that prints a count of how many occurrences of the letter "a" # there are in q. Do to this you will have to use a loop within a loop. q = ["apple", "beans", "orange", "tangerine", "butter", "watermelon", "vinegar"] # Type your answer here:

  • For Python: (Use # comments to explain each line) Write code that prints an octagon shape...

    For Python: (Use # comments to explain each line) Write code that prints an octagon shape using stars, by prompting the user for the octagon side length.   For example: "How long should each side of the octagon be? " Then takes this input, and prints an octagon in stars using the user input.

  • Write a program that prints an imitation of the Composition II in Red, Blue, and Yellow...

    Write a program that prints an imitation of the Composition II in Red, Blue, and Yellow created in 1930 by Piet Mondrian painting, illustrated below. Use character sequences such as @@a or: to indicate different colors and use - and| to form the black lines. with algorithm public class Solution - public static void main(String[] args) { for(int FI ;İ<-50;İ++){ for(int Hj<-50;jt+){ if(j-12) { System.out.print("! "); } else ifj>12 && і 39){ System.out.print("@ "); 3 else if(i--39)\ System.out.print( "-"); }...

  • 10. What prints when the following code is executed? public static void main (String args) "Cattywampus"; for (...

    10. What prints when the following code is executed? public static void main (String args) "Cattywampus"; for (int i-s.length )-1 i> 0 i-2) if (s.charAt (i)a') System.out.print(""); ] else if (s.charAt (i)'t') System.out.print (s.charAt (i-2)) i+ti else System. out. print (s . charAt (İ) ) ; if (i<2) System.out.print ("y"); System.out.println () 10. What prints when the following code is executed? public static void main (String args) "Cattywampus"; for (int i-s.length )-1 i> 0 i-2) if (s.charAt (i)a') System.out.print(""); ]...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT