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
Write a class called Dragon. A Dragon should have a name, a level, and a boolean variable, canBreatheFire, indicating whether or
Alex Ar [27]

Answer: A dragon name could be name Holls and at level 14 and can breathe fire

Explanation:

4 0
3 years ago
What is the on board storage C:
sasho [114]
On-board? im assuming so. an on-board storage is where people keep luggage/items on a ship.

hopefully i could help ;)
7 0
3 years ago
What is the best scenerio for
Stels [109]

Answer:

the teacher said a (dash) reads pages on website pls answer me now i have to write it now

5 0
2 years ago
Read 2 more answers
Which element can be changed using the Print pane? Check all that apply.
Ronch [10]

Answer:

B

C

D

E

Explanation:

5 0
3 years ago
Read 2 more answers
Flowchart is written using english language.<br>true or false​
DedPeter [7]

the answer is true hope it helps

7 0
3 years ago
Read 2 more answers
Other questions:
  • You just brought a new hard drive for your computer. U plan to use this as a secondary hard drive to store all your uma files. O
    10·1 answer
  • The 2 main types of copyright relevant to the recording industry?
    5·2 answers
  • Application software definition word excel powerpoint microsoft
    13·1 answer
  • When security issues are a special concern, companies want to take extra steps to make sure that transmissions can’t be intercep
    7·1 answer
  • Determine the number of cache sets (S), tag bits (t), set index bits (s), and block offset bits (b) for a 1024-byte 4-way set as
    5·1 answer
  • What is episodic memory? knowledge about words, concepts, and language-based knowledge and facts information about events we hav
    10·1 answer
  • BUURTAIS
    7·1 answer
  • The output for the following code will be: Pasta (1 mark)
    6·1 answer
  • Compared to using a command line, an advantage to using an operating system that employs a gui is ________.
    5·1 answer
  • each data mining technique has its advantages and limitations. which data mining technique mimics the neural structure of the br
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!