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
What are some examples of productions categorized as non-broadcast productions?
leonid [27]

Answer:

Non-broadcast media incorporates

  • Recorded television
  • Radio
  • Podcasts
  • Internet
  • Streaming services.

Explanation:

Non-broadcast media is a phrase used to represent audio and visual communications that can be obtained at any moment. Non-broadcast media is the knowledge that can be switched on and off, suspended, rewound, and fast-forwarded at certain times.

Examples of non-broadcast productions

Non-broadcast media incorporates

  • Recorded television
  • Radio
  • Podcasts
  • Internet
  • Streaming services.

To learn more about broadcast productions refer:

  • https://brainly.in/question/17335292
  • https://brainly.in/question/44811105

4 0
3 years ago
Question 1 of 10 Which type of information systems personnel are involved in organizing information so that users can access it
sergij07 [2.7K]
Option D is correct. If we want multiple users to access data, we will organise that data in Database we can then be accessed whenever needed.
6 0
3 years ago
Suppose you want to view a document that has several headings. what view would you use?
bija089 [108]
Um i think outline. :)
5 0
3 years ago
Let x = ["Red", 2.55,"Green", 3,"Black","false"], then solve the following:
blagie [28]

Answer:

  • Print(x) would be directly calling the x variable so it would print everything but the []
  • Print(x[10]) is calling the number 10 which results in E
  • 2 + d= 2d

3 0
3 years ago
There is no reason to study the works of famous photographers because they will make you less creative.
weeeeeb [17]
I think it is true because you may be ‘inspired’ by a famous artist but if you’re always being inspired by others its not 100% yours / you being creative
8 0
3 years ago
Read 2 more answers
Other questions:
  • Which set of steps will organize the data to only show foods with more than 100 calories and rank their sugar content from great
    8·1 answer
  • Which technology forms the foundation for cloud computing? forms the foundation for cloud computing.
    12·2 answers
  • A customer in a store is purchasing 5 items. Write a python program that asks for the price of each item and display the subtota
    14·1 answer
  • The counter in a for or while loop can have an explicit increment: for i=m:k:n. This advances the counter i by increment k each
    15·1 answer
  • Making the data impossible to recover even by applying physical forensics methods is known as __________ of media.
    13·1 answer
  • Which routing protocol does an exterior router use to collect data to build its routing tables?
    8·1 answer
  • #Write a function called alter_list. alter_list should have#two parameters: a list of strings and a list of integers.##The list
    11·1 answer
  • A program that allows employees to choose their starting and ending times, as long as they are at work during a specified core p
    8·1 answer
  • In what type of attack does the attacker have the ciphertext of several messages that were encrypted with the same encryption al
    14·1 answer
  • Golf scores record the number of strokes used to get the ball in the hole. The expected number of strokes varies from hole to ho
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!