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
You are a disgruntled employee with a master’s degree in computer sciences who was recently laid off from a major technology com
WARRIOR [948]

Answer:

If you know what you're doing, I'd suggest hacking into the company's website...

Explanation:

3 0
3 years ago
Can you please answer the question in the picture ! :)
Ilya [14]

Answer:

Explanation: If and else statements are one of the most important parts of programming.

1. You add an if you do something if a condition is met. For example, if number of chocolates equals zero( a condition), and inside you can do something like buy more chocolates. And else statement happens if the if condition isn't met and you want to the code to do something else. You don't need this if you don't want anything to happen if the if condition isn't true.

2. This might be used in a number guessing game. Let's say you have to guess a number, if its correct the computer should correct but if you get it wrong it should display wrong. You can write if the number the user writes in equal to the number you are supposed to guess say correct. Else say wrong

Hope this helps. Please mark as brainliest! Thanks!

4 0
3 years ago
Who where the romanovs? What happened to them ?
Vikentia [17]
They where high ranking aristocrats in Russia during the 16th century. They where all executed.
5 0
3 years ago
A certain computer has a 4meg address space. how many bits wide is this computer's address bus?
PIT_PIT [208]
22 bits






-----------------------------------
4 0
2 years ago
1.5 Code Practice: Question 1
Jobisdone [24]
What’s the question?
Always remember to add any reasonable information for someone to help or answer!!

Have a good rest of your day.
6 0
2 years ago
Other questions:
  • The computers that run the DBMS and all devices that store database data should reside in locked, controlled-access facilities.
    15·1 answer
  • Certain medications can increase risk of obtaining a sunburn true or false
    12·1 answer
  • You view a portion of a document on the screen through a ____.
    6·1 answer
  • What is internet marketing??
    13·1 answer
  • Cine stie repede va rog mult si repede
    9·1 answer
  • We can create tables in MS. Word from *<br> 2 points<br> Insert Tab<br> Home Tab<br> Mailings Tab
    5·2 answers
  • A. All methods in an interface must be _________________ _________________________.
    5·1 answer
  • The computer stores currently used programs and data in ________.
    9·2 answers
  • Discuss new concepts that you have learned about Cisco Devices and how they will be helpful in the workplace.
    11·1 answer
  • This question involves the creation and use of a spinner to generate random numbers in a game. a gamespinner object represents a
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!