Write a code snippet that prompts the user for an integer named number and prints out “Good Number” if the input meets any one the following conditions, and prints out “Bad Number” if it does not :number equals 5number equals 7number is between 10 and 20 (non-inclusive)number is greater than 30.

Question
Asked Dec 8, 2019
28 views
  1. Write a code snippet that prompts the user for an integer named number and prints out “Good Number” if the input meets any one the following conditions, and prints out “Bad Number” if it does not :
        • number equals 5
        • number equals 7
        • number is between 10 and 20 (non-inclusive)
        • number is greater than 30.
check_circle

Expert Answer

Step 1

Following is the python program that takes input from user and print Yes if the number meets any of the following conditions else print No.

  • number equals 5 
  • number equals 7 
  • the number is between 10 and 20 (non-inclusive) 
  • the number is greater than 30

 

Approach:

 

  • Prompt user to enter any number.
  • Save it in variable named number. Use if condition to check if the number meets any of the given conditions.
  • Or is used inside if statement because for the number to be Good it needs to meet any of the conditions.
  • Finally print number as good or bad according to condition.

 

Step 2

Code:

#prompt user to input any number and save it in variable named number

number = int(input("Enter a number: "))

#using if condition to check if the number meets any of the condition given

if(number==5 or number==7 or (number>10 and number<20) or number>30):

    #if the entered ...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Science

Programing Language

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: x = 2, y =1, z =3, what is the value of x, y, z after executing the following codes? switch(x) { cas...

A: Code (in java)-class Main{public static void main (String [] args){int x = 2, y =1, z =3;//initializ...

question_answer

Q: Simplify the following Boolean functions F = AC' + B'D + A'CD + ABCD   And draw the simplified funct...

A: Given expression:

question_answer

Q: - Find the employee in each department who makes the highest salary in their departments

A: To find the highest salary in each department.Left join is to be used to both the table together.Gro...

question_answer

Q: Write code to complete DoublePennies()'s base case. Sample output for below program:Number of pennie...

A: Answer:The condition for finding total pennies is as follows:if(numDays == 0){  totalPennies = numPe...

question_answer

Q: Exercise 1 Consider a hash table of size 13, and assume open addressing with linear probing   Show ...

A:  As the given size of the table is 13, as well as the number of elements to be inserted in the table...

question_answer

Q: In a computer instruction format, the instruction length is 10 bits and the size of an addressfield ...

A:  Total number of instructions =210=1024Size of address field=3 bitsAnd the instruction length is 10 ...

question_answer

Q: What is function overloading? Explain with help of example?

A: Polymorphism:It is an essential feature of OOPS which allows the object to act differently in the di...

question_answer

Q: What is the output of the following program? #include &lt;iostream&gt; using namespace std; void...

A: Modifying the given program code with comments and proper displaying statement:Program code: //inclu...

question_answer

Q: Which is the following is true? 1.The 80/20 rule states that 80% of the instruction is executed and ...

A: Answer:80/20 rule was first introduced by Vilfredo Pareto and therefore in also commonly known as Pa...