Conditional statement that will prevent users from imputing

  • Thread starter GreenPrint
  • Start date
  • Tags
    Conditional
In summary, the conversation is about finding a conditional statement that will prevent users from inputting non-integer inputs. The goal is to prompt the user to enter a number in a loop and display an error message if a non-integer is entered. Suggestions are made for using INT() or floor() functions, and it is mentioned that it would be helpful if there were a function to punish users for not following directions.
  • #1
GreenPrint
1,196
0

Homework Statement



I was wondering if anyone knows of a conditional statement that will prevent users from imputing non integer inputs.

like for example
z=0
while z<1
x=input('Enter Something')
if SOME MAGICAL CONDITIONAL STATEMENT
disp('You entered a invalid entry. Please try again.')
else
z=1;
end
end

I hope you get what I'm trying to do. In a loop prompt a user to enter a number. If the user enters a number like 5.5 I would like the message to come up 'You entered a invalid entry. Please try again.' by using some conditional statement

anyone got any ideas?

Homework Equations





The Attempt at a Solution

 
Physics news on Phys.org
  • #2


Does the computer language that you're using have INT() or floor() functions?
 
  • #3


It's too bad most programming languages don't have a built-in function which tases users who don't follow directions.
 

What is a conditional statement?

A conditional statement is a programming concept that allows the computer to make decisions based on certain conditions. It consists of a condition or set of conditions that are evaluated, and a block of code that is executed if the condition is true.

Why is it important to prevent users from inputting?

Preventing users from inputting certain values or types of data helps to ensure the accuracy and reliability of the program. It can also prevent errors or crashes that may occur if invalid input is entered.

How can a conditional statement prevent users from inputting?

A conditional statement can be used to check the value of user input and determine if it meets certain criteria. If the input does not meet the criteria, the program can display an error message or prompt the user for valid input.

What are some common conditions used in conditional statements to prevent user input?

Some common conditions used in conditional statements for preventing user input include checking for empty or null values, ensuring that the input is within a certain range or type, and checking for specific patterns or formats in the input.

Are there any limitations to using conditional statements for preventing user input?

While conditional statements can be effective in preventing certain types of user input, they are not foolproof and may not catch all possible errors or invalid input. It is important to thoroughly test and validate user input in addition to using conditional statements.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
10
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
22
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
9
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
8
Views
6K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
Back
Top