1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
sukhopar [10]
3 years ago
11

Write a program using Python that prompts for an integer and prints the integer, but if something other than an integer is input

, the program keeps asking for an integer. Here is a sample session:
Input an integer: abc

Error: try again.

Input an integer: 4a

Error: try again.

Input an integer: 2.5

Error: try again.

Input an integer: 123

The integer is: 123
Computers and Technology
2 answers:
Tcecarenko [31]3 years ago
7 0

Answer:

#program in Python

#read until user Enter an integer

while True:

   #try block to check integer

   try:

       #read input from user

       inp = int(input("Enter an integer: "))

       #print input

       print("The integer is: ",inp)

       break

   #if input is not integer

   except ValueError:

       #print message

       print("Wrong: try again.")

Explanation:

In try block, read input from user.If the input is not integer the print a message  in except block.Read the input until user enter an integer. When user enter an  integer then print the integer and break the loop.

Output:

Enter an integer: acs                                                                                                      

Wrong: try again.                                                                                                          

Enter an integer: 4a                                                                                                      

Wrong: try again.                                                                                                          

Enter an integer: 2.2                                                                                                      

Wrong: try again.                                                                                                          

Enter an integer: 12                                                                                                      

The integer is:  12  

trasher [3.6K]3 years ago
3 0

Answer:

Enter an integer: 4a                                                                                                      

Wrong: try again.                                                                                                          

Enter an integer: 2.2                                                                                                      

Wrong: try again.                                                                                                          

Enter an integer: 12                                                                                                      

The integer is:  12  

hope this helps

You might be interested in
Given that add, a function that expects two integer parameters and returns their sum, and given that two variables, euro_sales a
Evgesh-ka [11]

Answer:

int eurasia_sales = add(euro_sales,asia_sales);

Explanation:

Kindly find the explanation attached

Download txt
7 0
4 years ago
For security reasons, the network administrator needs to prevent pings into the corporate networks from hosts outside the intern
VikaD [51]

Answer:

ICMP

Explanation:

3 0
3 years ago
Type the correct answer in each box. Spell all words correctly. Programmers utilize to convert a program from language, which is
natulia [17]

Answer: Binary

Explanation: Binary is a system of 1s and 0s that tell the system when and where to flip a digital switch very fast

3 0
3 years ago
In every programming language, when you access data stored in an array, you must use a ____ containing a value that accesses mem
Juli2301 [7.4K]

Answer: this app allow  u to have answers made for students 5 star ap but there are some ads that get  in the way

Explanation:

but it is good

7 0
3 years ago
What are lexical errors?<br> and fi(a==b)<br> will it be a lexical error or a syntactical error?
blondinia [14]
Lexical errors are rejected and unrecognized particular syntax. The numbers you put will be recognized and also the letters will be recognized. And everything else is rejected. The given opreation will be recognized as syntax error because the whole format is wrong even the operation given.
3 0
3 years ago
Other questions:
  • Write a program that takes nouns and forms their plurals on the basis of these rules:
    8·1 answer
  • Choose the answer that best explains why Morse's invention of the telegraph changed media forever.
    11·2 answers
  • Question 2: Sum of consecutive odd View Past Answers No past answers. Write a program which asks user to enter an integer n, cal
    8·2 answers
  • A weak fuel to air mixture along with normal airflow through a turbine engine may result in?
    8·1 answer
  • A(n) __________ is a recording of a motion picture, or television program for playing through a television.
    8·2 answers
  • A slideshow that accompanies an oral report is known as what?
    6·1 answer
  • Omar is preparing to deliver a presentation to his class. It is about a program to collect samples from an asteroid that has bee
    13·1 answer
  • Do you think that dealing with big data demands high ethical regulations, accountability, and responsibility of the person as we
    7·1 answer
  • A pedometer treats walking 2,000 steps as walking 1 mile. Write a program whose input is the number of steps, and whose output i
    14·1 answer
  • Match each method of communication with its intended purpose.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!